-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEligibility.java
76 lines (65 loc) · 1.45 KB
/
Eligibility.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
import java.util.Scanner;
class NotEligibleException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public String toString() {
return "Not Eligible";
}
}
class LowAttendanceException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public String toString() {
return "Insufficient Attendance";
}
}
class LowMarksException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public String toString() {
return "Insufficient Marks";
}
}
class Exam {
int marks, attendance;
public Exam() {}
public Exam(int marks, int attendance) {
this.marks = marks;
this.attendance = attendance;
}
void amiIEligibile() throws NotEligibleException {
NotEligibleException ne = new NotEligibleException();
if(marks < 20) {
ne.initCause(new LowMarksException());
throw ne;
}
else if(attendance < 80) {
ne.initCause(new LowAttendanceException());
throw ne;
}
else {
System.out.println("Congrats! you are Eligible!");
}
}
}
public class Eligibility {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Marks and Attedance : ");
int marks = in.nextInt(), attendance = in.nextInt();
Exam student = new Exam(marks, attendance);
try {
student.amiIEligibile();
} catch (NotEligibleException e) {
e.printStackTrace();
System.out.println(e.getCause());
}
in.close();
}
}