-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentAverageAndGrade.java
60 lines (45 loc) · 1.61 KB
/
StudentAverageAndGrade.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
import java.util.Scanner;
public class StudentAverageAndGrade {
public static Student studentDetails() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter id:");
int id = scanner.nextInt();
System.out.println("Entername:");
String name = scanner.next();
int subjects = 0;
while (true) {
System.out.println("Enter no of subjects:");
subjects = scanner.nextInt();
if (subjects <= 0) {
System.out.println("Invalid");
} else {
break;
}
}
int[] marks = new int[subjects];
for (int i = 0; i < subjects; ++i) {
int mark = 0;
while (true) {
System.out.println("Enter mark for subject " + (i + 1) + ":");
mark = scanner.nextInt();
if (mark < 0 || mark > 100) {
System.out.println("Invalid Mark");
} else {
break;
}
}
marks[i] = mark;
}
Student student = new Student(id, name, marks);
return student;
}
public static void main(String[] args) {
Student student = studentDetails();
student.calculateAvg();
student.findGrade();
System.out.println("Id:" + student.getId());
System.out.println("Name:" + student.getName());
System.out.println("Average:" + student.getAverage());
System.out.println("Grade:" + student.getGrade());
}
}