GradeDistribution
which keeps the number of As, Bs, Cs, Ds, and Fs there are in a class (just the number of letter grades, not the number grades). You will then implement methods for this class which printout the total number of grades in the class (that is, the total number of students), a nice text-y bar chart, and the median grade. For example, the following code:public static void main(String[] args) { GradeDistribution grades = new GradeDistribution(); grades.setAs(4); grades.setBs(10); grades.setCs(11); grades.setDs(1); grades.setFs(5); //print a pretty graph System.out.println(grades); System.out.println("There are a total of " + grades.getNumGrades() + " grades."); System.out.println("The median grade is " + grades.getMedian()); grades.setAs(20); grades.setBs(15); grades.setCs(10); grades.setDs(5); grades.setFs(0); System.out.println(grades); System.out.println("There are a total of " + grades.getNumGrades() + " grades."); System.out.println("The median grade is " + grades.getMedian()); }
should print out:
**** A ********** B *********** C * D ***** F There are a total of 31 grades. The median grade is C ******************** A *************** B ********** C ***** D F There are a total of 50 grades. The median grade is B
Tip: The median grade is the one in the middle (plus or minus one) if you lay them all out in order (from F to A, or A to F). To calculate it just find the middle position and then...find the grade that is in the middle. For example, if everyone got A's then the median grade is an A, if 20 people got A's and 10 got B's then the median is an A, etc.
As always, turn it in on the dropbox.cse.sc.edu.
No comments:
Post a Comment