forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdded CGPA Calculator in Java
47 lines (36 loc) · 1.18 KB
/
Added CGPA Calculator in Java
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
import java.util.Scanner;
class CGPACalculator {
private double[] marks;
public CGPACalculator(double[] marks) {
this.marks = marks;
}
public double calculateCGPA() {
double totalGradePoints = 0.0;
for (double mark : marks) {
double grade = mark / 10.0;
totalGradePoints += grade;
}
return totalGradePoints / marks.length;
}
public double calculatePercentage() {
double cgpa = calculateCGPA();
return cgpa * 9.5;
}
}
public class CGPA {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of subjects:");
int n = sc.nextInt();
double[] marks = new double[n];
System.out.println("Enter marks:");
for (int i = 0; i < n; i++) {
marks[i] = sc.nextDouble();
}
CGPACalculator calculator = new CGPACalculator(marks);
double cgpa = calculator.calculateCGPA();
System.out.println("CGPA: " + cgpa);
double percentage = calculator.calculatePercentage();
System.out.println("Percentage from CGPA: " + percentage);
}
}