-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment2.java
More file actions
105 lines (92 loc) · 3.25 KB
/
assignment2.java
File metadata and controls
105 lines (92 loc) · 3.25 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// package java_programming;
import java.util.*;
class stud {
int roll_no, sub1, sub2, sub3, sub4, sub5, percentage;
String name, grade;
static List<stud> list_of_obects = new ArrayList<stud>();
stud(int R, String N, int s1, int s2, int s3, int s4, int s5) {
this.roll_no = R;
this.name = N;
this.sub1 = s1;
this.sub2 = s2;
this.sub3 = s3;
this.sub4 = s4;
this.sub5 = s5;
this.percentage = (s1 + s2 + s3 + s4 + s5) / 5;
if (percentage >= 90) {
this.grade = "A";
} else if (percentage >= 70 && percentage < 90) {
this.grade = "B";
} else {
this.grade = "C";
}
list_of_obects.add(this);
}
stud() {
}
void display() {
System.out.println("\n\nName\t\tRoll No\t Sub1 \tSub2 \tSub3 \tSub4 \tSub5 \tPercentage \t\tGrade");
for (stud stud : list_of_obects) {
System.out.print("\n");
System.out.print(stud.name);
System.out.print("\t\t");
System.out.print(stud.roll_no);
System.out.print("\t");
System.out.print(stud.sub1);
System.out.print("\t");
System.out.print(stud.sub2);
System.out.print("\t");
System.out.print(stud.sub3);
System.out.print("\t");
System.out.print(stud.sub4);
System.out.print("\t");
System.out.print(stud.sub5);
System.out.print("\t");
System.out.print(stud.percentage);
System.out.print("\t\t\t");
System.out.print(stud.grade);
}
}
}
public class assignment2 {
public static void main(String arg[]) {
Scanner input = new Scanner(System.in);
int choice = 0;
while (choice != 3) {
System.out.println("\n\t\t\t\t\t***Menu***");
System.out.print("1)Enter New Entry\n2)Show all records\n3)Exit\n-:");
choice = input.nextInt();
switch (choice) {
case 1: {
int roll_no, sub1, sub2, sub3, sub4, sub5;
String name;
System.out.println("\n\t\tEnter Information--:");
System.out.print("Name :");
name = input.next();
System.out.print("Roll Number :");
roll_no = input.nextInt();
System.out.print("Subject 1 :");
sub1 = input.nextInt();
System.out.print("Subject 2 :");
sub2 = input.nextInt();
System.out.print("subject 3 :");
sub3 = input.nextInt();
System.out.print("Subject 4 :");
sub4 = input.nextInt();
System.out.print("Subject 5 :");
sub5 = input.nextInt();
stud new_stud = new stud(roll_no, name, sub1, sub2, sub3, sub4, sub5);
break;
}
case 2: {
stud new_stud = new stud();
new_stud.display();
break;
}
default:
break;
}
}
input.close();
}
}