-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab2Q2.java
More file actions
51 lines (40 loc) · 1.35 KB
/
Copy pathLab2Q2.java
File metadata and controls
51 lines (40 loc) · 1.35 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
50
51
import java.util.Scanner;
class Student {
int roll, no_of_subs;
String name;
int marks;
int[] credits;
int totalCredit;
int total;
public void Credits() {
Scanner sc = new Scanner(System.in);
System.out.println("Enter roll no.");
roll=sc.nextInt();
System.out.println("Enter no. of subjects");
no_of_subs = sc.nextInt();
credits = new int[no_of_subs];
for (int i = 1; i <= no_of_subs; i++) {
System.out.println("Enter Marks of subject " + i + " (out of 100)");
marks = sc.nextInt();
int gradepts = marks / 10;
System.out.println("GP for subject " + i + " is " + gradepts);
System.out.println("Enter Credits for subject " + i);
credits[i - 1] = sc.nextInt();
totalCredit += credits[i - 1];
int subjectTotal = credits[i - 1] * gradepts;
System.out.println("credit*GP for sub " + i + " is " + subjectTotal);
total += subjectTotal;
}
if (totalCredit == 0) {
System.out.println("CPI = 0.0");
} else {
System.out.println("CPI = " + (double) total / totalCredit);
}
}
}
public class Lab2Q2 {
public static void main(String[] args) {
Student s1 = new Student();
s1.Credits();
}
}