Repository navigation
Expand file tree
/
Copy pathStudentMarks.java
More file actions
80 lines (60 loc) · 1.76 KB
/
Copy pathStudentMarks.java
File metadata and controls
80 lines (60 loc) · 1.76 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
package extra;
import java.util.Scanner;
class NegativeValuesException extends Exception {
public NegativeValuesException() {
super();
System.out.println("NegativeValuesException occured");
}
}
class ValuesOutOfRangeException extends Exception {
public ValuesOutOfRangeException() {
super();
System.out.println("ValuesOutOfRangeException occured");
}
}
public class StudentMarks {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 2; i++) {
String name = "";
int subA = 0;
int subB = 0;
int subC = 0;
try {
name = sc.nextLine();
if (sc.hasNextInt())
subA = sc.nextInt();
else
throw new NumberFormatException();
if (sc.hasNextInt())
subB = sc.nextInt();
else
throw new NumberFormatException();
if (sc.hasNextInt())
subC = sc.nextInt();
else
throw new NumberFormatException();
if (subA < 0) throw new NegativeValuesException();
if (subA > 100) throw new ValuesOutOfRangeException();
if (subB < 0) throw new NegativeValuesException();
if (subB > 100) throw new ValuesOutOfRangeException();
if (subC < 0) throw new NegativeValuesException();
if (subC > 100) throw new ValuesOutOfRangeException();
}
catch (ArithmeticException e) {
System.out.println(e.getMessage());
}
catch (NegativeValuesException e) {
System.out.println(e.getMessage());
}
catch (ValuesOutOfRangeException e) {
System.out.println(e.getMessage());
}
System.out.println("Name: " + name);
System.out.println("Marks of subject A: " + subA);
System.out.println("Marks of subject B: " + subB);
System.out.println("Marks of subject C: " + subC);
}
sc.close();
}
}