File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java.util.Scanner;
2
+
3
+ class CGPACalculator {
4
+ private double[] marks;
5
+
6
+ public CGPACalculator(double[] marks) {
7
+ this.marks = marks;
8
+ }
9
+
10
+ public double calculateCGPA() {
11
+ double totalGradePoints = 0.0;
12
+ for (double mark : marks) {
13
+ double grade = mark / 10.0;
14
+ totalGradePoints += grade;
15
+ }
16
+ return totalGradePoints / marks.length;
17
+ }
18
+
19
+ public double calculatePercentage() {
20
+ double cgpa = calculateCGPA();
21
+ return cgpa * 9.5;
22
+ }
23
+ }
24
+
25
+ public class CGPA {
26
+ public static void main(String[] args) {
27
+ Scanner sc = new Scanner(System.in);
28
+
29
+ System.out.println("Enter the number of subjects:");
30
+ int n = sc.nextInt();
31
+
32
+ double[] marks = new double[n];
33
+
34
+ System.out.println("Enter marks:");
35
+ for (int i = 0; i < n; i++) {
36
+ marks[i] = sc.nextDouble();
37
+ }
38
+
39
+ CGPACalculator calculator = new CGPACalculator(marks);
40
+
41
+ double cgpa = calculator.calculateCGPA();
42
+ System.out.println("CGPA: " + cgpa);
43
+
44
+ double percentage = calculator.calculatePercentage();
45
+ System.out.println("Percentage from CGPA: " + percentage);
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments