Jose Vidal shared this file. Want to do more with it?
/**
*GradeDistribution.java
*@authorJoseMVidal<jmvidal@gmail.com>
*Created on Feb9,2012
*
*/
publicclassGradeDistribution{
privateint a;
privateint b;
privateint c;
privateint d;
privateint f;
publicvoidsetAs(int a){
this.a = a;
}
publicvoidsetBs(int b){
this.b = b;
}
publicvoidsetCs(int c){
this.c = c;
}
publicvoidsetDs(int d){
this.d = d;
}
publicvoidsetFs(int f){
this.f = f;
}
publicintgetNumGrades(){
return a + b + c + d + f;
}
publicStringgetMedian(){
int midpoint =getNumGrades()/2;
int count = f;
if(count >= midpoint)
return"F";
count += d;
if(count >= midpoint)
return"D";
count += c;
if(count >= midpoint)
return"C";
count += b;
if(count >= midpoint)
return"B";
return"A";
}
privateStringgetStars(int x){
String result ="";
for(int i=0; i< x; i++)
result +="*";
return result;
}
publicStringtoString(){
returngetStars(a)+" A\n"+
getStars(b)+" B\n"+
getStars(c)+" C\n"+
getStars(d)+" D\n"+
getStars(f)+" F\n";
}
/**
*@param args
*/
publicstaticvoidmain(String[] args){
GradeDistribution grades =newGradeDistribution();
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());
}
}
We use cookies to provide, improve, protect and promote our services. Visit our Privacy Policy and Privacy Policy FAQs to learn more. You can manage your personal preferences, including your ‘Do not sell or share my personal data to third parties’ setting using the “Customize cookies” button below.