5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage.
Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math
2) Declare variable total and percentage
3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class
4) Calculate total of all classes
5) Calculate Percentage where total is divided by 500 and then multiplying by 100.
6) Declare if else statement where if percentage is greater than 90 you get A and do the same steps until you reach failing F point
7) Then display total points
8) After that display average of score which is percentage
Solution:
import java.util.*;
Class StudentGrades {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int English, Chemistry, Java, Physics, Maths, total = 0, percentage = 0;
System.out.println("Enter English grade: ");
English = sc.nextInt();
System.out.println("Enter Chemistry grade: ");
Chemistry = sc.nextInt();
System.out.println("Enter Java grade: ");
Java = sc.nextInt();
System.out.println("Enter Physics grade: ");
Physics = sc.nextInt();
System.out.println("Enter Maths grade: ");
Maths = sc.nextInt();
total = English + Chemistry + Java + Physics + Maths;
percentage = (total/500)*100;
if(percentage >= 90) {
System.out.println("A Grade:);
} else if(percentage >= 80 && percentage < 90) {
System.out.println("B Grade");
} else if(percentage >= 70 && percentage < 80) {
System.out.println("C Grade");
} else if(percentage >=60 && percentage < 70) {
System.out.println("D Grade");
} else if(percentage >=50 && percentage < 60) {
System.out.println("E Grade");
} else {
System.out.println("F Grade");
}
System.out.println("Total points :" + total);
System.out.println("Average score: " + total/5);
return;
}
}
Get Answers For Free
Most questions answered within 1 hours.