-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankNew.java
More file actions
73 lines (62 loc) · 1.91 KB
/
BankNew.java
File metadata and controls
73 lines (62 loc) · 1.91 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
70
71
72
73
package PracticePrograms;
import java.util.Scanner;
public class BankNew {
static Scanner scanner = new Scanner(System.in);
static double balance = 0;
public static void main(String[] args){
boolean run = true;
int choice;
double deposit = 0;
while(run) {
System.out.print("""
\n***************
BANKING PROGRAM
***************
1. Show Balance
2. Deposit
3. Withdraw
4. Exit
***************
Enter your choice (1-4):""");
choice = scanner.nextInt();
switch (choice) {
case 1 -> showBalance(balance);
case 2 -> {
balance += deposit();
System.out.print("New Balance: ₹" + balance);
}
case 3 -> {
balance -= withdraw();
System.out.print("New Balance: ₹" + balance);
}
case 4 -> run = false;
default -> System.out.print("Invalid Choice");
}
}
}
static void showBalance(double balance){
System.out.printf("₹%.2f\n", balance);
}
static double deposit(){
double amount;
System.out.print("Enter deposit amount: ");
amount = scanner.nextDouble();
if(amount < 0) {
System.out.print("Invalid amount\n");
return 0;
}else {
return amount;
}
}
static double withdraw(){
double amount;
System.out.print("Enter Withdraw amount: ");
amount = scanner.nextDouble();
if(amount > 0 && amount <= balance){
return amount;
}else{
System.out.print("invalid amount\n");
return 0;
}
}
}