Edit: Oh, nvm. I just redid the code and figured out how to write the tester class. Sorry guys for the trouble:( This thread can be deleted.
So I have this code (not all was written by me).
But I don't know how to start writing a tester class for it.
It asks: first, ask the user for all student names. Then read in the scores for all quizzes, prompting for the score of each student. Finally, print the names of all students and their final scores.
Here's the GradeBook.java:
import java.util.*;
import java.lang.*;
/**
this class makes a gradebook you can modify the gradebook however you like and you can ask for individual's grade or a class as a collective.
*/
public class GradeBook
{
//instance variables
private ArrayList<ArrayList> gradeBook;
private ArrayList<String> students;
/**
this method creates a new object that holds student grades
*/
public GradeBook()
{
gradeBook = new ArrayList<ArrayList>();
students = new ArrayList<String>();
}
/**
This adds a new score to a student's name or array
@param name is the students name
@param score is the score that you add to the student's name
*/
public void addScore(String name, double score)
{
if(!students.contains(name))
{
ArrayList<Double> currentScore = new ArrayList<Double>();
students.add(name);
currentScore.add(score);
gradeBook.add(currentScore);
}
else
{
int indexOfStudent = 0;
indexOfStudent = students.indexOf(name);
ArrayList<Double> currentScores = new ArrayList<Double>();
currentScores = gradeBook.get(indexOfStudent);
currentScores.add(score);
gradeBook.set(indexOfStudent, currentScores);
}
}
/**
finds the sum of an individual's scores
@param name name of the student
*/
public double individualSum(String name)
{
int indexOfStudent = 0;
indexOfStudent = students.indexOf(name);
double sum = 0.0;
ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(indexOfStudent);
for(int i = 0; i < studentScores.size(); i++)
{
sum += studentScores.get(i);
}
return sum;
}
/**
Using a neutral indexing of the sum of all student
@param j is the index of all the students
*/
public double sum(int j)
{
double sum = 0.0;
ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(j);
for(int i = 0; i < studentScores.size(); i++)
{
sum += studentScores.get(j);
}
return sum;
}
/**
finding the minimum of the student's scores
@param name the students name of which is being refered to
*/
public double individualMinimum(String name)
{
int indexOfStudent = 0;
indexOfStudent = students.indexOf(name);
double minNum = 0.0;
ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(indexOfStudent);
for(int i = 0; i < studentScores.size() - 1; i++)
{
minNum = Math.min(studentScores.get(i), studentScores.get(i + 1));
}
return minNum;
}
public double minimum(int j)
{
double minNum = 0.0;
ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(j);
for(int i = 0; i < studentScores.size() - 1; i++)
{
minNum = Math.min(studentScores.get(i), studentScores.get(i + 1));
}
return minNum;
}
public double finalScore(String name)
{
int indexOfStudent = 0;
indexOfStudent = students.indexOf(name);
ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(indexOfStudent);
if(studentScores.size() == 0)
return 0;
else if (studentScores.size() == 1)
return studentScores.get(0);
else
return individualSum(name) - individualMinimum(name);
}
public double allfinalScores(int i)
{
ArrayList<Double> studentScores = new ArrayList<Double>();
studentScores = gradeBook.get(i);
if(studentScores.size() == 0)
return 0;
else if (studentScores.size() == 1)
return studentScores.get(0);
else
return sum(i) - minimum(i);
}
public String toString()
{
String allOfGradeBook = "";
for(int i = 0; i < students.size(); i++)
{
allOfGradeBook += students.get(i) + " " + allfinalScores(i);
if(i + 1 != students.size())
allOfGradeBook += "\n";
}
return allOfGradeBook;
}
}