Drill5Solutions

Drill5Solutions - public class GradeBook cfw_ double...

Info iconThis preview shows pages 1–2. 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};
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Page1 / 3

Drill5Solutions - public class GradeBook cfw_ double...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online