-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTASK2.java
More file actions
56 lines (48 loc) · 1.51 KB
/
TASK2.java
File metadata and controls
56 lines (48 loc) · 1.51 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
52
53
54
55
56
import java.util.Scanner;
class Grade{
public String grade(int avgp){
switch (avgp / 10) {
case 10:
return "A+";
case 9:
return "A";
case 8:
return "B+";
case 7:
return "B";
case 6:
return "C";
case 5:
return "D";
default:
return "F";
}
}
}
public class TASK2{
public static void main(String[] args){
Grade g = new Grade();
Scanner sc = new Scanner(System.in);
//Taking input of how many subjects are there
System.out.print("Enter the no. of subjects : ");
int tsubs = sc.nextInt();
int tmarks = 0;
//Taking and adding all the marks
for (int i = 0; i < tsubs; i++) {
System.out.println("Enter the marks obtained in subject " + (i + 1) + " (out of 100) : ");
int marks = sc.nextInt();
tmarks += marks;
}
//Calculating Percentage
int avgp = tmarks / tsubs;
//Calculating Grades
String Grade = g.grade(avgp);
//Displaying all the Data
System.out.println();
System.out.println("Total marks obtained :- " + tmarks);
System.out.println("Percentage obtained :- " + avgp+"%");
System.out.println("Grade obtained :- " + Grade);
sc.close();
//Lets test the code
}
}