Complete the following Programming Exercise: Design a class named Grades with th
ID: 3590610 • Letter: C
Question
Complete the following Programming Exercise: Design a class named Grades with the following grading policies: a) There are two quizzes, each graded on the basis of 10 points b) There is one midterm exam and one final exdm, each graded on the basis of 100 points. c) The Final counts as 50% of the grade, midterm 25% and the two quizzes 25% (do not forget to normalize the quiz scores. They should be converted to a percentage before are average in.) Any grade above 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, any grade below 60 is an F. The implementation class must have accessors (getters) and mutators (setters) for all instance variables, a method named CalculateGrade that returns the final grade, and a method name Displaylnfo to display the student's information. Write a testing class named GradesTest that initializes all values in the constructor, display the information. Then, program will prompt the user to enter new data (full name, student ID and scores). Finally, output the student's record, which will consist of two quizzes, midterm and final scores as well as the student's average numeric score for the entire course and final letter grade. Remember, the final grade, average and letter grade is not part of the constructor.Explanation / Answer
//Grades.java file
public class Grades {
String name;
int student_id;
float q1_score,q2_score,mid_term_score,final_exm_score;
float final_grade;
char final_grade_letter;
public Grades() {
}
public Grades(String s_name,int s_id,float q1,float q2,float mid,float final_exm){ //Constructor to initialize all inputs
name=s_name;
student_id=s_id;
q1_score=q1;
q2_score=q2;
mid_term_score=mid;
final_exm_score=final_exm;
}
public float getQ1_score() {
return q1_score;
}
public void setQ1_score(float q1_score) {
this.q1_score = q1_score;
}
public float getQ2_score() {
return q2_score;
}
public void setQ2_score(float q2_score) {
this.q2_score = q2_score;
}
public float getMid_term_score() {
return mid_term_score;
}
public void setMid_term_score(float mid_term_score) {
this.mid_term_score = mid_term_score;
}
public float getFinal_exm_score() {
return final_exm_score;
}
public void setFinal_exm_score(float final_exm_score) {
this.final_exm_score = final_exm_score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getStudent_id() {
return student_id;
}
public void setStudent_id(int student_id) {
this.student_id = student_id;
}
public char calculateGrade(){
final_grade=(final_exm_score/2)+(mid_term_score/4)+((q1_score*10)+(q2_score*10))/8; // 50% final exm scr + 25% mid term score + 25 % of normalized quizzes score
if(final_grade>=90){
final_grade_letter='A';
}else if(final_grade<90 && final_grade>=80){
final_grade_letter='B';
}else if(final_grade<80 && final_grade>=70){
final_grade_letter='C';
}else {
final_grade_letter='F';
}
return final_grade_letter;
}
public void displayInfo(){
System.out.println("Student ID: "+getStudent_id());
System.out.println("Name: "+getName());
System.out.println("Quizz 1 score: "+getQ1_score()+ " / 10");
System.out.println("Quizz 2 score: "+getQ2_score()+ " / 10");
System.out.println("Mid Term exm Score: "+getMid_term_score()+" /100");
System.out.println("Final Term exm Score: "+getFinal_exm_score()+" /100");
System.out.println("Final average: "+final_grade);
System.out.println("Final Grade letter: "+final_grade_letter);
}
}
//GradesTest.java file
import java.util.Scanner;
public class GradesTest {
public static void main(String args[]){
Grades student=new Grades("Alice",1,5,8,80,95); //using constructor to input values
student.calculateGrade(); //will return the grade letter; if needed,we can print this
student.displayInfo(); //will print every details of the student including the results
try{
Scanner scanner=new Scanner(System.in); // initializing a scanner to read inputs from the user;
Grades student2=new Grades();
System.out.println("Enter student name");
student2.setName(scanner.nextLine());
System.out.println("Enter student id");
student2.setStudent_id(scanner.nextInt());
System.out.println("Enter q1 score");
float tmp=scanner.nextFloat();
if(tmp>10 || tmp<0){
System.out.println("Invalid score input"); //if user tries to enter scores more than 10 or less than 0
System.exit(0);
}else{
student2.setQ1_score(tmp);
}
System.out.println("Enter q2 score");
tmp=scanner.nextFloat();
if(tmp>10 || tmp<0){
System.out.println("Invalid score input");
System.exit(0);
}else{
student2.setQ2_score(tmp);
}
System.out.println("Enter mid term score");
tmp=scanner.nextFloat();
if(tmp>100 || tmp<0){
System.out.println("Invalid score input");
System.exit(0);
}else{
student2.setMid_term_score(tmp);
}
System.out.println("Enter final term score");
tmp=scanner.nextFloat();
if(tmp>100 || tmp<0){
System.out.println("Invalid score input");
System.exit(0);
}else{
student2.setFinal_exm_score(tmp);
}
student2.calculateGrade();
student2.displayInfo();
}catch(Exception e){
System.out.println("ERROR...Invalid details supplied");
}
}
}