Question
package toBeCompleted.stage3; import java.util.*; import toBeCompleted.stage1.Assessment; import toBeCompleted.stage2.GradebookEntry; public class Gradebook { private ArrayList assessments; private ArrayList records; /** * DO NOT MODIFY * @return
package toBeCompleted.stage3;
import java.util.*;
import toBeCompleted.stage1.Assessment;
import toBeCompleted.stage2.GradebookEntry;
public class Gradebook {
private ArrayList
private ArrayList
/**
* DO NOT MODIFY
* @return number of records
*/
public int numberOfRecords() {
return records.size();
}
/**
* DO NOT MODIFY
* @return number of assessments
*/
public int numberOfAssessments() {
return assessments.size();
}
/**
* DO NOT MODIFY
*/
public String toString() {
String header1 = "Asssessment title: \t";
String header2 = "Asssessment worth: \t";
double totalWorth = 0;
for(Assessment a: assessments) {
header1 = header1 + a.getTitle() + "\t";
header2 = header2 + "(" + a.getWorth() + ")\t";
totalWorth += a.getWorth();
}
header2 = header2 + "(Total "+totalWorth+")";
String data = records.toString();
data = data.replace("[", "");
data = data.replace("]", "");
data = data.replaceAll(", ", "");
return header1+" "+header2+" "+data;
}
/**
* make a deep copy of the parameters into the instance variables
* @param c
* @param r
*/
public Gradebook(ArrayList
//to be completed
}
/**
*
* @param recordNumber
* @return true if the given record number is valid.
* For example, if there are 9 records, valid record numbers
* are from 0 to 8 (including 0 and 8)
*/
public boolean isValidRecordNumber(int recordNumber) {
return false; //to be completed
}
/**
*
* @param assessmentNumber
* @return true if assessmentNumber is valid, false otherwise
*/
public boolean isValidAssessmentNumber(int assessmentNumber) {
return false; //to be completed
}
/**
*
* @param assessmentTitle
* @return how much is the assessment worth. return null if assessment not found
*/
public Double getWorth(String assessmentTitle) {
return null; //to be completed
}
/**
* sort the records in descending order of totals.
* hint: you can use the method compareTo from class GradebookEntry
*/
public void sortRecords() {
//to be completed
}
/**
*
* @param title
* @return index of assessment with given title. return -1 if no such title exists
*/
public int getAssessmentIndex(String title) {
return 0; //to be completed
}
/**
* scale marks of a particular assessment, whose title is provided
* by the given factor (1.2 means increase by 20%, 0.75 means decrease by 25%).
* note that marks should have an upper bound of what that particular assessment is worth,
* and a lower bound of 0. Thus, a mark of 4 out of 5, with a factor of 0.5, should become 5 (and not 6).
* Similarly, a mark of 2 out of 5, with a factor = -1.5, should become 0 (and not -1).
* do nothing if there is no assessment with the given title
* @param title
* @param factor
*/
public void scale(String title, double factor) {
//to be completed
}
/**
* D/HD
* sort the assessments in ascending order of how much they are worth.
* Note that each record should be updated as well.
*/
public void sortAssessments() {
//to be completed
}
/**
* D/HD
* set the marks of student with the given name in the assessment with the
* title of assessmentTitle to given marks
* @param name: name of student
* @param assessmentTitle: title of assessment
* @param marks: marks to be set for the given student and assignment
*/
public void setMarks(String name, String assessmentTitle, double marks) {
//to be completed
}
/**
*
* @param idx
* @return GradebookEntry at given index if index is valid, return null otherwise
*/
public GradebookEntry getRecord(int idx) {
return null; //to be completed
}
/**
*
* @param idx
* @return Assessment at given index if index is valid, return null otherwise
*/
public Assessment getAssessment(int idx) {
return null; //to be completed
}
/**
*
* @param name
* @param title
* @return mark of student with given name in an assessment with given title.
* return null if no such record exists.
*/
public Double getMark(String name, String title) {
return null; //to be completed
}
/**
*
* @param name
* @return record for student with given name. return null if no such record exists
*/
public GradebookEntry getRecord(String name) {
return null; //to be completed
}
}
***TEST***
//DO NOT MODIFY THIS FILE
package doNotModify.tests;
import static org.junit.Assert.*;
import java.io.FileNotFoundException;
import org.junit.Before;
import org.junit.Test;
import doNotModify.reader.DataReader;
import toBeCompleted.stage2.GradebookEntry;
import toBeCompleted.stage3.Gradebook;
public class GradebookTest {
private Gradebook book;
@Before
public void setup() throws FileNotFoundException {
book = DataReader.getGradeBook("data.csv");
}
@Test
public void testGradebook() {
assertEquals(7, book.numberOfRecords());
assertEquals(6, book.numberOfAssessments());
}
@Test
public void testNumberOfRecords() {
assertEquals(7, book.numberOfRecords());
}
@Test
public void testNumberOfAssessments() {
assertEquals(6, book.numberOfAssessments());
}
@Test
public void testIsValidRecordNumber() {
assertTrue(book.isValidRecordNumber(0));
assertTrue(book.isValidRecordNumber(6));
assertFalse(book.isValidRecordNumber(-1));
assertFalse(book.isValidRecordNumber(7));
}
@Test
public void testIsValidAssessmentNumber() {
assertTrue(book.isValidAssessmentNumber(0));
assertTrue(book.isValidAssessmentNumber(5));
assertFalse(book.isValidAssessmentNumber(-1));
assertFalse(book.isValidAssessmentNumber(6));
}
@Test
public void testGetWorth() {
assertEquals(15, book.getWorth("PE2"), 0.001);
assertEquals(25.1, book.getWorth("PE3"), 0.001);
assertEquals(null, book.getWorth("PE5"));
}
@Test
public void testSortRecords() {
book.sortRecords();
for(int i=1; i < book.numberOfRecords(); i++) {
assertTrue(book.getRecord(i).getTotal() <= book.getRecord(i-1).getTotal());
}
//sorted based on averages
}
@Test
public void testScale() {
assertEquals(10.0, book.getRecord(0).getMark(4), 0.001);
assertEquals(3, book.getRecord(1).getMark(4), 0.001);
assertEquals(7, book.getRecord(2).getMark(4), 0.001);
assertEquals(0, book.getRecord(3).getMark(4), 0.001);
assertEquals(9, book.getRecord(4).getMark(4), 0.001);
assertEquals(7.5, book.getRecord(5).getMark(4), 0.001);
assertEquals(0, book.getRecord(6).getMark(4), 0.001);
book.scale("A2", 1.2);
assertEquals(10.0, book.getRecord(0).getMark(4), 0.001); //should not change. already max
assertEquals(3.6, book.getRecord(1).getMark(4), 0.001); //should have become 3.6 from 3
assertEquals(8.4, book.getRecord(2).getMark(4), 0.001);
assertEquals(0, book.getRecord(3).getMark(4), 0.001);
assertEquals(10, book.getRecord(4).getMark(4), 0.001);
assertEquals(9, book.getRecord(5).getMark(4), 0.001);
assertEquals(0, book.getRecord(6).getMark(4), 0.001);
}
@Test
public void testSortAssessments() {
book.sortAssessments();
for(int i=1; i < book.numberOfAssessments(); i++) {
assertTrue(book.getAssessment(i).getWorth() >= book.getAssessment(i-1).getWorth());
}
}
@Test
public void testGetRecord() {
GradebookEntry record = book.getRecord("Joey Tribiani");
assertNull(record);
record = book.getRecord("Angelo Provolone");
assertEquals(9, record.getId());
}
@Test
public void testSetMarks() {
assertEquals(0, book.getMark("Angelo Provolone", "PE4"), 0.001);
book.setMarks("Angelo Provolone", "PE4", 13.14);
assertEquals(13.14, book.getMark("Angelo Provolone", "PE4"), 0.001);
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started