-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCGPACalculator.java
More file actions
50 lines (41 loc) · 1.33 KB
/
CGPACalculator.java
File metadata and controls
50 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
import java.lang.*;
public class CGPACalculator {
public static void main(String[] args) {
System.out.println("Grade to Point Conversion Table:");
System.out.println("O : 10");
System.out.println("A+: 9");
System.out.println("A : 8");
System.out.println("B+: 7");
System.out.println("B : 6");
System.out.println("C+: 5");
System.out.println("C : 4");
System.out.println("D : 0");
System.out.println("UA : 0");
Scanner sc = new Scanner(System.in);
System.out.println("Enter a Number of Subjects: ");
int number_of_subject = sc.nextInt();
double totalGradePoint = 0;
double totalCredits = 0;
for(int i=1;i<=number_of_subject;i++){
//System.out.print("Subject"+i+": ");
//String Subject_name = sc.next();
System.out.print("Enter grade (on a scale of 0 to 10): ");
double grade = sc.nextDouble();
System.out.print("Enter a Subject Credits: ");
double credit = sc.nextDouble();
totalGradePoint += grade * credit;
totalCredits += credit;
}
if(totalCredits > 0)
{
double cgpa = totalGradePoint / totalCredits;
System.out.printf("\nYour CGPA is: %.2f\n", cgpa);
}
else
{
System.out.println("\nTotal credits cannot be zero. Please check your inputs.");
}
sc.close();
}
}