In: Computer Science
Write a grading program for a class with the following grading policies:
There are three quizzes, each graded on the basis of 10 points.
There is one miterm exm, graded on the basis of 100 points.
There is one finl exm, graded on the basis of 100 points.
The fnal exm counts for 40% of the grade. The miterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade. (Do not forget to convert the quiz scores to percentages before they are averaged in.)
Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program should read in the student’s scores and output the student’s record, which consists of three quiz scores and two exm scores, as well as the student’s overall numeric score for the entire course and final letter grade.
Define and use a class for the student record. The class should have instance variables for the quizzes, midterm, final, overall numeric score for the course, and final letter grade. The overall numeric score is a number in the range 0 to 100, which represents the weighted average of the student’s work. The class should have methods to compute the overall numeric grade and the final letter grade. These last methods should be void methods that set the appropriate instance variables. Your class should have a reasonable set of accessor and mutator methods, an equals method, and a toString method, whether or not your program uses them. You may add other methods if you wish.
JAVA!
Have a look at the below code. I have put comments wherever required for better understanding.
class Student{
// instance variables
int quiz1,quiz2,quiz3;
int midSem;
int finalExam;
int overallScore;
char grade;
// setters
public void setQuiz1(int x){
this.quiz1 = x;
}
public void setQuiz2(int y){
this.quiz2 = y;
}
public void setQuiz3(int z){
this.quiz2 = z;
}
public void setmidSem(int m){
this.midSem = m;
}
public void setFinalExam(int f){
this.finalExam = f;
}
// getters
public int getQuiz1(){
return this.quiz1;
}
public int getQuiz2(){
return this.quiz2;
}
public int getQuiz3(){
return this.quiz3;
}
public int getmidSem(){
return this.midSem;
}
public int getFinalExam(){
return this.finalExam;
}
public int getOverallScore(){
return this.overallScore;
}
public int getGrade(){
return this.grade;
}
public int quizAverage(){
int total = 0;
total+= (this.quiz1/10)*100;
total+= (this.quiz2/10)*100;
total+= (this.quiz2/10)*100;
return total/3;
}
public int overAll(){
int total = 0;
total+=0.4*finalExam;
total+=0.35*midSem;
total+=0.25*quizAverage();
return total;
}
public setGrade(){
int finalScore = overAll();
if (finalScore>=90){
this.grade = 'A';
}
else if(finalScore>=80){
this.grade = 'B';
}
else if(finalScore>=70){
this.grade = 'C';
}
else if(finalScore>=60){
this.grade = 'D';
}
else{
this.grade = 'F';
}
}
public String toString(){//overriding the toString() method
return quiz1 + quiz2 + quiz3 + midSem + finalExam;
}
}
Happy Learning!