-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankingApp.java
77 lines (67 loc) · 2.78 KB
/
BankingApp.java
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
import java.util.Scanner;
public class BankingApp {
private static double balance = 0.0;
private static void checkBalance() {
System.out.printf("Your current balance is: Rs%.2f\n", balance);
}
private static void depositMoney(Scanner scanner) {
System.out.print("Enter the amount to deposit: ");
double amount = scanner.nextDouble();
if (amount > 0) {
balance += amount;
System.out.printf("Successfully deposited Rs%.2f. Your new balance is: Rs%.2f\n", amount, balance);
} else {
System.out.println("Deposit amount must be greater than zero.");
depositMoney(scanner);
}
}
private static void withdrawMoney(Scanner scanner) {
System.out.print("Enter the amount to withdraw: ");
double amount = scanner.nextDouble();
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.printf("Successfully withdrew Rs%.2f. Your new balance is: Rs%.2f\n", amount, balance);
} else if (amount > balance) {
if(balance <= 0) {
System.out.println("Your account balance is " + balance + ",Please deposit some money in your account");
}
else {
System.out.println("Insufficient balance. Please try a smaller amount.");
withdrawMoney(scanner);
}
} else {
System.out.println("Withdrawal amount must be greater than zero.");
withdrawMoney(scanner);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean running = true;
System.out.println("Welcome to Simple Banking Application!");
while (running) {
System.out.println("\nPlease choose an option:");
System.out.println("Press 1 to Check Balance");
System.out.println("Press 2 to Deposit Money");
System.out.println("Press 3 to Withdraw Money");
System.out.println("Press 4 to Exit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
checkBalance();
break;
case 2:
depositMoney(scanner);
break;
case 3:
withdrawMoney(scanner);
break;
case 4:
System.out.println("Thank you for using Simple Banking Application. Have a nice day!");
running = false;
break;
default:
System.out.println("Invalid option. Please try again.");
}
}
}
}