-
Notifications
You must be signed in to change notification settings - Fork 0
/
GradeTracker.java
70 lines (56 loc) · 1.63 KB
/
GradeTracker.java
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
package sgt;
import java.util.*;
class StudentGradeTracker{
public static void main(String [] args) {
Scanner sc=new Scanner(System.in);
//initialization of variables
String stud_name,grade;
int sub_number;
// user input students name
System.out.println("enter the student name");
stud_name=sc.nextLine();
// number of subjects to be entered
System.out.println("enter the number of subjects: ");
sub_number=sc.nextInt();
if(sub_number<=0) {
System.out.println("Invalid Input: Number of subjects must be greater than 0");
}
int totalMarks=0;
int MaxMarksPerSubjects=100;
// to get user marks input of different subjects
for(int i=1; i<=sub_number; i++) {
System.out.print("Students marks in subject " + i + " (out of 100): ");
int marks=sc.nextInt();
if(marks < 0 || marks > MaxMarksPerSubjects) {
System.out.print("Invalid Marks");
i--;
}
else {
totalMarks+=marks;
}
}
System.out.println();
// to calculate the average marks
double avgMarks=(double) totalMarks/(sub_number* MaxMarksPerSubjects)*100;
// Grade calculation
if ( avgMarks >=90 && avgMarks<=100 ) {
grade="A";
}
else if( avgMarks >= 70 && avgMarks<90 ) {
grade="B";
}
else if (avgMarks>=40 && avgMarks<70 ){
grade="C";
}
else if(avgMarks <40 && avgMarks>=30) {
grade="D";
}
else {
grade="E";
}
// to calculate GPA
double gpa=avgMarks/10;
// output
System.out.println("Student Name: "+ stud_name +"\n"+ "Average Marks: " + avgMarks +"\n"+ "Grade: " + grade +"\n"+ "GPA: " + gpa);
}
}