-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask2.java
More file actions
64 lines (56 loc) · 1.77 KB
/
Task2.java
File metadata and controls
64 lines (56 loc) · 1.77 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
57
58
59
60
61
62
63
64
import java.util.Scanner;
public class Task2 {
static Scanner sc = new Scanner(System.in);
public int[] sub = new int[8];
public static String[] subName = {"SEPA", "CN", "TOC", "AI", "WEB", "MiniPro", "RE", "EVS"};
public int total;
public double avg = 0;
public String g;
public void inputMark() {
System.out.println("Enter the marks in following subject:");
for (int i = 0; i < sub.length; i++) {
System.out.print(subName[i] + ":");
sub[i] = sc.nextInt();
if (sub[i] < 0 || sub[i] > 100) {
System.out.println("Invalid marks!...Enter again.");
i--;
}
System.out.print("\n");
}
}
public int totalMark() {
total = 0;
for (int i = 0; i < sub.length; i++) {
total += sub[i];
}
return total;
}
public void calculatePercentage() {
avg = (double) ((double) total / 800) * 100;
System.out.println((int) avg + "%");
}
public void grade() {
if (avg >= 90) {
System.out.println("Grade=A+");
} else if (avg >= 80) {
System.out.println("Grade=A");
} else if (avg >= 70) {
System.out.println("Grade=B+");
} else if (avg >= 60) {
System.out.println("Grade=B");
} else if (avg >= 50) {
System.out.println("Grade=C+");
} else if (avg >= 40) {
System.out.println("Grade=C");
} else {
System.out.println("Fail");
}
}
public static void main(String[] args) {
Task2 t2 = new Task2();
t2.inputMark();
System.out.println("Total Marks: " + t2.totalMark());
t2.calculatePercentage();
t2.grade();
}
}