-
Notifications
You must be signed in to change notification settings - Fork 25
/
Balance_addition.java
56 lines (49 loc) · 1.34 KB
/
Balance_addition.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
package Exception_Handling;
import java.util.Scanner;
class ExceededMaximumAmount extends Exception
{
public ExceededMaximumAmount(String s)
{
super(s);
}
}
public class Balance_addition
{
int balance;
public Balance_addition(int balance)
{
this.balance = balance;
}
void BalanceCheck() throws ExceededMaximumAmount
{
if (balance > 20000)
{
int FixedDeposit = balance - 20000;
int balance = 20000;
String output = ("Your account balance is more than 20K now, so creating FD of amount: " + FixedDeposit);
throw new ExceededMaximumAmount(output);
}
else
{
System.out.println("Total account balance: " + balance);
}
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
Balance_addition obj = new Balance_addition(15000);
System.out.println("Your account balance is : " + obj.balance);
System.out.println("Please enter the amount to add in your balance: ");
int add = sc.nextInt();
obj.balance = obj.balance + add;
try
{
obj.BalanceCheck();
}
catch (ExceededMaximumAmount ex)
{
System.out.println(ex.getMessage());
}
sc.close();
}
}