Hey all, I'm in an intro class for Java in University and I'm pretty confused with Objects. Current assignment is to have a program remember, and keep track of students who have gotten As, Bs, Cs, Ds, and Fs.
So far I have gotten the program to remember grades through if - else if statements. However I now need to have the program provide the percentage of those who have gotten As through Fs.
Here is what I have for my working page for reference.
Thanks in advanced.
*****************************************
public class GradeDistribution {
//Instance Variables
public int As, Bs, Cs, Ds, Fs, getTotal, addGrade, grade;
public double percentAs, percentBs, percentCs, percentDs, percentFs;
//Constructor
public GradeDistribution() {
As = 0;
Bs = 0;
Cs = 0;
Ds = 0;
Fs = 0;
}
//Getters
public int getAs() {
return As;
}
public int getBs() {
return Bs;
}
public int getCs() {
return Cs;
}
public int getDs() {
return Ds;
}
public int getFs() {
return Fs;
}
public double percentAs() {
return percentAs;
}
public double percentBs() {
return percentBs;
}
public double percentCs() {
return percentCs;
}
public double percentDs() {
return percentDs;
}
public double percentFs() {
return percentFs;
}
public int getTotal() {
getTotal = As+Bs+Cs+Ds+Fs;
return getTotal;
}
public void addGrade(int addGrade) {
if (addGrade >= 80 && addGrade <= 100) {
As++;
} else if (addGrade >= 70 && addGrade < 80) {
Bs++;
} else if (addGrade >= 60 && addGrade < 70) {
Cs++;
} else if (addGrade >= 50 && addGrade < 60) {
Ds++;
} else if (addGrade >= 0 && addGrade < 50) {
Fs++;
}
}
public void reset() {
}
//Bar Graph
public void print() {
System.out.println("0 10 20 30 40 50 60 70 80"
+ " 90 100");
System.out.println("|_____|_____|_____|_____|_____ |_____|_____|_____|"
+ "_____|_____|");
}
}