-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask2.java
More file actions
81 lines (75 loc) · 1.91 KB
/
Copy pathtask2.java
File metadata and controls
81 lines (75 loc) · 1.91 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.*;
/*
* Grading System percentage wise
* 96-100 A+
* 91-95 A
* 81-90 B+
* 71-80 B
* 61-70 C+
* 51-60 C
* 41-50 D
* <40 Fail
* */
public class task2 {
static int subCou;
static float [] marks;
static Scanner sc = new Scanner(System.in);
//Using recursion for getting correct marks
static void forInput (int index, float value) {
if (value >= 101 || value <=-1) {
System.out.println("incorrect input enter correct marks!!!");
System.out.print("Subject "+index+" :- ");
marks[index-1]=sc.nextFloat();
forInput(index, marks[index-1]);
}
}
static String gradeAssign (float total ) {
if(total>=96 && total<=100) {
return "A+";
}
else if(total>=91 && total<=95) {
return "A";
}
else if(total>=81 && total<=90) {
return "B+";
}
else if(total>=71 && total<=80) {
return "B";
}
else if(total>=61 && total<=70) {
return "C+";
}
else if(total>=51 && total<=60) {
return "C";
}
else if(total>=41 && total<=50) {
return "D";
}
else {
return "F (FAIL)";
}
}
public static void main(String[] args) {
float total=0;
System.out.println("******* GRADE CALCULATOR *******");
System.out.print("\nEnter Number of Subjects :- ");
subCou = sc.nextInt();
System.out.println();
System.out.println("******* ENTER MARKS *******\n");
marks = new float[subCou];
for (int i = 1; i <= subCou; i++) {
System.out.print("Subject "+i+" :- ");
marks[i-1]=sc.nextFloat();
task2.forInput(i, marks[i-1]);
}
System.out.println("\n******* RUSULT *******\n");
for (int i = 0; i < marks.length; i++) {
total+=(marks[i]);
}
System.out.println("Total marks = "+total+"\n");
float ans =(total/(subCou*100))*100;
System.out.printf("Percentage = %.2f",ans);
System.out.print(" %\n\n");
System.out.println("Grade = "+task2.gradeAssign(ans));
}
}