Skip to content

Commit a0fc10f

Browse files
committed
2 parents 6f52765 + 068f0e6 commit a0fc10f

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

Eligibility.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import java.util.Scanner;
2+
3+
class NotEligibleException extends Exception {
4+
public String toString() {
5+
return "Not Eligible";
6+
}
7+
}
8+
9+
class LowAttendanceException extends Exception {
10+
public String toString() {
11+
return "Insufficient Attendance";
12+
}
13+
}
14+
15+
class LowMarksException extends Exception {
16+
public String toString() {
17+
return "Insufficient Marks";
18+
}
19+
}
20+
21+
class Exam {
22+
int marks, attendance;
23+
public Exam() {}
24+
public Exam(int marks, int attendance) {
25+
this.marks = marks;
26+
this.attendance = attendance;
27+
28+
}
29+
void amiIEligibile() throws NotEligibleException {
30+
NotEligibleException ne = new NotEligibleException();
31+
if(marks < 20) {
32+
ne.initCause(new LowMarksException());
33+
throw ne;
34+
}
35+
else if(attendance < 80) {
36+
ne.initCause(new LowAttendanceException());
37+
throw ne;
38+
}
39+
else {
40+
System.out.println("Congrats! you are Eligible!");
41+
}
42+
}
43+
}
44+
45+
public class Eligibility {
46+
47+
public static void main(String[] args) {
48+
Scanner in = new Scanner(System.in);
49+
System.out.print("Enter Marks and Attedance : ");
50+
int marks = in.nextInt(), attendance = in.nextInt();
51+
Exam student = new Exam();
52+
try {
53+
student.amiIEligibile();
54+
} catch (NotEligibleException e) {
55+
e.printStackTrace();
56+
System.out.println(e.getCause());
57+
}
58+
}
59+
60+
}

EventOne.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import java.util.Scanner;
2+
3+
class DailyTransactionLimitException extends Exception {
4+
public String toString() {
5+
return "Daily Limit Exceeded (25,000)";
6+
}
7+
}
8+
9+
class InsufficientAmountException extends Exception {
10+
public String toString() {
11+
return "Insufficient Balance";
12+
}
13+
}
14+
15+
class Test {
16+
int balance;
17+
public Test() {}
18+
public Test(int initialBalance) {
19+
balance = initialBalance;
20+
}
21+
void withdraw(int amountToWithdraw) throws DailyTransactionLimitException, InsufficientAmountException {
22+
if(amountToWithdraw > 25000) {
23+
throw new DailyTransactionLimitException();
24+
}
25+
else if(amountToWithdraw > balance) {
26+
throw new InsufficientAmountException();
27+
}
28+
else {
29+
balance = balance - amountToWithdraw;
30+
System.out.println("WITHDRAWAL SUCCESSFUL !\n" + "Amount withdrawn : " + amountToWithdraw + "\nCurrent Balance : " + balance);
31+
}
32+
}
33+
}
34+
35+
public class EventOne {
36+
public static void main(String[] args) {
37+
Scanner in = new Scanner(System.in);
38+
System.out.print("Enter initial balance : ");
39+
int initialBalanceEnteredByUser = in.nextInt();
40+
Test atm = new Test(initialBalanceEnteredByUser);
41+
System.out.print("Enter amount to withdraw (daily limit 25K) : ");
42+
int amountToWithdraw = in.nextInt();
43+
try {
44+
atm.withdraw(amountToWithdraw);
45+
} catch (DailyTransactionLimitException e) {
46+
// TODO Auto-generated catch block
47+
e.printStackTrace();
48+
} catch (InsufficientAmountException e) {
49+
// TODO Auto-generated catch block
50+
e.printStackTrace();
51+
}
52+
}
53+
54+
}

0 commit comments

Comments
 (0)