-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProg4.java
More file actions
69 lines (68 loc) · 2.24 KB
/
Prog4.java
File metadata and controls
69 lines (68 loc) · 2.24 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
import java.util.Scanner;
class DemonetizationException extends Exception {
private int amount;
public DemonetizationException(int amount) {
this.amount = amount;
}
public String getMessage() {
return "Deposit of Old currency of Rs" + amount + " crosses Rs. 5,000 and cannot be Deposited";
}
}
class Account {
private static final int MIN_BALANCE = 500;
private int balance;
public Account() {
balance = MIN_BALANCE;
}
public void deposit(int amount, String currencyType) {
String curr = currencyType.toUpperCase();
if (curr.equals("OLD") && amount > 5000) {
try {
throw new DemonetizationException(amount);
} catch (DemonetizationException e) {
System.out.println(e.getMessage());
return;
}
}
balance += amount;
System.out.println("Deposit successful!");
}
public void currBalance() {
System.out.println("Current balance: Rs" + balance);
}
public void withdraw(int amount) {
if (balance - amount < MIN_BALANCE) {
System.out.println("Insufficient balance!");
return;
}
balance -= amount;
System.out.println("Withdrawal successful!");
}
}
class Prog4 {
public static void main(String[] args) {
Scanner inp=new Scanner(System.in);
Account acc= new Account();
while(true)
{
System.out.println("1.Deposit\n2.Current bal\n3.Withdraw\n4.Exit\nEnter your choice:");
int ch=inp.nextInt();
switch(ch)
{
case 1: System.out.println("Enter the amount to be deposited");
int amount=inp.nextInt();
System.out.println("Enter amount type");
String type=inp.next();
acc.deposit(amount,type);
break;
case 2: acc.currBalance();
break;
case 3: System.out.println("Enter amount to be withdrawn: ");
int amount1 = inp.nextInt();
acc.withdraw(amount1);
break;
case 4: System.exit(0);
}
}
}
}