-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
57 lines (53 loc) · 1.92 KB
/
Bank.java
File metadata and controls
57 lines (53 loc) · 1.92 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
package PracticePrograms;
import java.util.Scanner;
public class Bank {
public static void main(String[] args) {
double balance = 0;
double deposit = 0;
double withdraw = 0;
Scanner scanner = new Scanner(System.in);
boolean run = true;
while (run){
System.out.println("""
***************
BANKING PROGRAM
***************
1. Show Balance
2. Deposit
3. Withdraw
4. Exit
***************
Enter your choice (1-4):
""");
String inp = scanner.next();
switch (inp){
case "1" -> System.out.print("Your Balance is: ₹" + balance);
case "2" -> {
System.out.print("Enter amount to deposit: ");
deposit = scanner.nextDouble();
if(deposit > 0){
balance += deposit;
System.out.println("Your New Balance: ₹" + balance);
}else {
System.out.print("Invalid Amount to Deposit!");
}
}
case "3" -> {
System.out.print("Enter amount to withdraw: ");
withdraw = scanner.nextDouble();
if(withdraw > 0 && withdraw <= balance){
balance -= withdraw;
System.out.println("Your New Balance: ₹" + balance);
}else {
System.out.print("Insufficient amount");
}
}
case "4" -> {
System.out.print("Exiting");
run = false;
}
default -> System.out.print("invalid");
}
}
}
}