{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Drill5Solutions

Drill5Solutions - public class GradeBook cfw double grades...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
public class GradeBook { double grades[]; // pass the number of grades to be entered public GradeBook(int numGrades) { // allocate the space for the scores grades = new double[numGrades]; int i; // initialize the scores to 0 for(i=0;i<grades.length;i++) grades[i] = 0; } public void setGrade(int index, double g) { grades[index] = g; } public int findGrade(double g) { int i; int count = 0; for(i=0;i<grades.length;i++) if (g == grades[i]) count++; return count; } public double max() { int i; double max = grades[0]; for(i=1;i<grades.length;i++) if (max <= grades[i]) max = grades[i]; return max; } public double average() { double sum = 0; int i; for(i=0;i<grades.length;i++) sum += grades[i]; return sum / grades.length; } public String toHistogram() { // the labels for the grades String labels[] = {"A: ", "B: ", "C: ", "D: ", "F: "}; // counts holds the number of each grade seen so far int counts[] = {0, 0, 0, 0, 0}; // indeces[] tells which place in count to increment, based // on the grade. int indeces[] = {4,4,4,4,4,4,3,2,1,0,0}; int i; // count how many there are of each grade, put result in counts for(i=0;i<grades.length;i++) { int tens = ((int) grades[i])/10; if (tens < 11)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
counts[indeces[tens]]++; }
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}