-
Notifications
You must be signed in to change notification settings - Fork 0
/
4B-Account
104 lines (79 loc) · 2.37 KB
/
4B-Account
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package Balance;
import java.util.Scanner;
public class Account
{
double curBalance, amt;
Scanner sc = new Scanner(System.in);
public Account()
{
curBalance = 500;
}
void deposit()
{
System.out.println("Enter amount to deposit: ");
amt = sc.nextDouble();
curBalance += amt;
System.out.println("Current Balance is : " + curBalance);
}
void withdraw()
{
System.out.println("Enter amount to withdraw: ");
amt = sc.nextDouble();
try
{
if(curBalance - amt < 500)
throw LessBalanceException(amt);
curBalance -= amt;
System.out.println("Availabe balance is : " + curBalance);
}
catch(LessBalanceException e)
{
System.out.println(e);
}
}
void display_balance()
{
System.out.println("Available current blance is : " + curBalance);
}
}
//LessBalanceException class
package Balance;
public LessBalanceException extends Exception
{
//int amt;
LessBalanceException(double i)
{
System.out.println("Balance is less : " + i);
}
}
//Class For Main
package Balance;
import java.util.Scanner;
public class MainProgram
{
pubilc static void main(String args[])
{
double amt;
int ch; //for choice
Scanner sc = new Scanner(System.in);
Account a = new Account();
String menu = "1. Deposit\n2. Withdraw\n3. Balance\n4. Exit\n5. Exit\n\nEnter your choice: ";
while(true)
{
System.out.println(menu);
ch = sc.nextInt();
swtich(ch)
{
case 1: a.deposit();
break;
case 2: a.withdraw();
break;
case 3: a.display_balance();
break;
case 4: return;
default: System.out.println("Invalid Option");
break;
}
}
}
}