-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankingSystem.java
More file actions
59 lines (55 loc) · 2.4 KB
/
BankingSystem.java
File metadata and controls
59 lines (55 loc) · 2.4 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
import java.util.Scanner;
public class BankingSystem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double balance = 0.0;// initial balance
int choice;
System.out.println();
System.out.println("Simple Banking System");
System.out.println();
do {
System.out.println("\n Choose an option");
System.out.println("1.Deposit");
System.out.println("2.Withdraw");
System.out.println("3.Check Balance");
System.out.println("4.Exit");
System.out.println();
choice = sc.nextInt();
switch (choice) {
case 1:// deposit
System.out.println("Enter amount to deposit: ");
double deposit = sc.nextDouble();
if (deposit > 0) {
balance += deposit;
System.out.println("Amount deposited successfully");
System.out.println("Your current balance is:" + balance);
} else {
System.out.println("Invalid deposit amount");
}
break;
case 2:// withdraw
System.out.println("Enter the amount to withdraw");
double withdraw = sc.nextDouble();
if (withdraw > 0 && withdraw <= balance) {
balance = balance - withdraw;
System.out.println("Amount withdrawn successfully");
System.out.println("Your current balance is:" + balance);
} else if (withdraw > balance) {
System.out.println("Insufficient balance");
} else {
System.out.println("Invalid withdrawal amount");
}
break;
case 3:// check balance
System.out.println("Your current balance is: " + balance);
break;
case 4:// Exit
System.out.println(
"Thank you so much for using my simple banking system. I appreciate it.\n Garima Thapa");
break;
default:
System.out.println("Invalid choice .please try again.");
}
} while (choice != 4);
}
}