-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
67 lines (64 loc) · 2.84 KB
/
Main.java
File metadata and controls
67 lines (64 loc) · 2.84 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Bank bank = new Bank();
while (true) {
System.out.println("\n1. Create Account");
System.out.println("2. Deposit");
System.out.println("3. Withdraw");
System.out.println("4. Check Balance");
System.out.println("5. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume the newline character
switch (choice) {
case 1:
System.out.print("Enter account number: ");
String accountNumber = scanner.nextLine();
bank.createAccount(accountNumber);
break;
case 2:
System.out.print("Enter account number: ");
accountNumber = scanner.nextLine();
BankAccount depositAccount = bank.getAccount(accountNumber);
if (depositAccount != null) {
System.out.print("Enter amount to deposit: ");
double depositAmount = scanner.nextDouble();
depositAccount.deposit(depositAmount);
} else {
System.out.println("Account not found.");
}
break;
case 3:
System.out.print("Enter account number: ");
accountNumber = scanner.nextLine();
BankAccount withdrawAccount = bank.getAccount(accountNumber);
if (withdrawAccount != null) {
System.out.print("Enter amount to withdraw: ");
double withdrawAmount = scanner.nextDouble();
withdrawAccount.withdraw(withdrawAmount);
} else {
System.out.println("Account not found.");
}
break;
case 4:
System.out.print("Enter account number: ");
accountNumber = scanner.nextLine();
BankAccount balanceAccount = bank.getAccount(accountNumber);
if (balanceAccount != null) {
System.out.println("Current Balance: $" + balanceAccount.getBalance());
} else {
System.out.println("Account not found.");
}
break;
case 5:
System.out.println("Exiting...");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}