forked from SLIIT-FacultyOfComputing/sliit-faculty-of-computing-se2012-ooad-practical-02-SE2012-OOAD-Practical_002
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMarks.java
187 lines (160 loc) · 6.93 KB
/
Marks.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import java.util.Scanner;
public class Marks {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int[][] details;
int n;
System.out.println("Enter the number of students:");
n = scanner.nextInt();
details = new int[n][3];
while(true)
{
System.out.println("\n");
System.out.println("1. Add student marks: add [studentID]");
System.out.println("2. Update student mark : update [studentID] [subjectID]");
System.out.println("3. Get the average for a subject: average_s [studentID]");
System.out.println("4. Get the average for a student: average [studentID]");
System.out.println("5. Get the total mark of a student : total [studentID]");
System.out.println("6. Display the grades");
System.out.println("7. Exit");
System.out.println("Enter your choice:");
int choice = scanner.nextInt();
int studentID;
int subjectID;
int sum;
double average;
String grade;
switch(choice)
{
case 1:
System.out.println("Enter the student ID 1 to "+ n );
studentID = scanner.nextInt()-1;
if(studentID>=0 && studentID<n)
{
System.out.println("Enter marks for Mathematics:");
details[studentID][0] = scanner.nextInt();
System.out.println("Enter marks for Chemistry:");
details[studentID][1] = scanner.nextInt();
System.out.println("Enter marks for Physics:");
details[studentID][2] = scanner.nextInt();
System.out.println("Marks added for student " + (studentID+1) + ".");
}
else
{
System.out.println("Invaid student ID.");
}
break;
case 2:
System.out.println("Enter the student ID 1 to "+ n );
studentID = scanner.nextInt() - 1;
if (studentID >= 0 && studentID < n) {
System.out.println("Enter the subject ID (0 -> Mathematics, 1 -> Chemistry, 2 -> Physics):");
subjectID = scanner.nextInt();
if (subjectID >= 0 && subjectID < 3) {
System.out.println("Enter new mark:");
details[studentID][subjectID] = scanner.nextInt();
System.out.println("Marks updated for student " + (studentID + 1) + " in subject " + subjectID + ".");
} else {
System.out.println("Invalid subject ID.");
}
} else {
System.out.println("Invalid student ID.");
}
break;
case 3:
System.out.println("Enter the subject ID (0 -> Mathematics, 1 -> Chemistry, 2 -> Physics):");
subjectID = scanner.nextInt();
if (subjectID >= 0 && subjectID < 3)
{
sum = 0;
for (int i = 0; i<n ; i++)
{
sum += details[i][subjectID];
}
average = sum/(double)n;
System.out.println("average for a subject :" + average + " : " + (subjectID + 1) );
}
else
{
System.out.println("Invalid subject ID.");
}
break;
case 4:
System.out.println("Enter the student ID 1 to "+ n );
studentID = scanner.nextInt() - 1;
if (studentID >= 0 && studentID < n)
{
sum = 0;
for (int i = 0; i<3 ; i++)
{
sum += details[studentID][i];
}
average = sum/3;
System.out.println("average for a student :" + average + " : " + (studentID + 1) );
}
else
{
System.out.println("Invalid student ID.");
}
break;
case 5:
System.out.println("Enter the student ID 1 to "+ n );
studentID = scanner.nextInt() - 1;
if (studentID >= 0 && studentID < n)
{
sum = 0;
for (int i = 0; i<3 ; i++)
{
sum += details[studentID][i];
}
System.out.println("Total mark of a student :" + sum + " : " + (studentID + 1) );
}
else
{
System.out.println("Invalid student ID.");
}
break;
case 6:
System.out.println("Student ID | Mathematics | Chemistry | Physics |");
for (int i = 0; i < n; i++)
{
System.out.print(" " + (i + 1) + " |");
for (int j = 0; j < 3; j++)
{
int score = details[i][j];
if (score >= 90)
{
grade = "Grade A";
}
else if (score >= 80)
{
grade = "Grade B";
}
else if (score >= 70)
{
grade = "Grade C";
}
else if (score >= 60)
{
grade = "Grade D";
}
else
{
grade = "Fail";
}
System.out.print(" " + grade + " |");
}
System.out.println();
}
break;
case 7:
System.out.println("Exit...");
scanner.close();
return;
default:
System.out.println("Invalid choice.");
}
}
}
}