Skip to content

Commit 1f5e386

Browse files
committed
Third recorded day
1 parent d64ead3 commit 1f5e386

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

BankingProgram.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import java.util.Scanner;
2+
3+
public class BankingProgram {
4+
static Scanner scanner = new Scanner(System.in);
5+
public static void main(String[] args) {
6+
// Banking Program
7+
8+
int choice;
9+
double balance = 0;
10+
boolean isRunning = true;
11+
12+
while(isRunning) {
13+
14+
System.out.println("*****************");
15+
System.out.println("Banking Program");
16+
System.out.println("1. Show Balance");
17+
System.out.println("2. Deposit");
18+
System.out.println("3. Withdraw");
19+
System.out.println("4. Exit");
20+
System.out.println("*****************");
21+
System.out.print("Enter your choice (1/2/3/4): ");
22+
choice = scanner.nextInt();
23+
switch(choice){
24+
case 1 -> showBalance(balance);
25+
case 2 -> {
26+
balance += deposit();
27+
System.out.printf("New Balance = $%.2f\n", balance);
28+
}
29+
case 3 -> {
30+
balance -=withdraw(balance);
31+
}
32+
case 4 -> isRunning = false;
33+
default -> System.out.println("Enter a valid choice!");
34+
}
35+
}
36+
37+
System.out.println("Thank you! Have a nice day!");
38+
39+
scanner.close();
40+
}
41+
static void showBalance(double balance) {
42+
System.out.printf("Account Balance: $%.2f\n", balance);
43+
}
44+
static double deposit() {
45+
46+
double amount;
47+
48+
System.out.print("Enter the amount you want to deposit: ");
49+
amount = scanner.nextDouble();
50+
51+
if(amount < 0) {
52+
System.out.println("Amount cannot be negative");
53+
return 0;
54+
} else {
55+
return amount;
56+
}
57+
}
58+
static double withdraw(double balance) {
59+
60+
double amount;
61+
62+
System.out.print("Enter the amount you want to withdraw: ");
63+
amount = scanner.nextDouble();
64+
65+
if(amount < 0) {
66+
System.out.println("Amount cannot be negative");
67+
return 0;
68+
} else if (amount > balance) {
69+
System.out.println("Insufficient funds!");
70+
return 0;
71+
} else {
72+
return amount;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)