In: Computer Science
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt user for input. When done it should give an option to compute another GPA or exit.
Greetings!!
Please find the basic solution below.
Happy Learning!!
Solution:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int count, i;
float totalMarks = 0, percentage, average;
Scanner scanner;
scanner = new Scanner(System.in);
System.out.println("Enter Number of Subject");
count = scanner.nextInt();
System.out.println("Enter Marks of " + count + " Subject");
for (i = 0; i < count; i++) {
totalMarks += scanner.nextInt();
}
System.out.println("Total MArks : " + totalMarks);
// Each subject is of 100 Marks
percentage = (totalMarks / (count * 100)) * 100;
/* Printing grade of a student using switch case statement */
switch ((int) percentage / 10) {
case 9:
System.out.println("Grade : A+");
break;
case 8:
case 7:
System.out.println("Grade : A");
break;
case 6:
System.out.println("Grade : B");
break;
case 5:
System.out.println("Grade : C");
break;
default:
System.out.println("Grade : D");
break;
}
}
}