-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBank.java
100 lines (91 loc) · 3.39 KB
/
Bank.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.util.Scanner;
public class Bank {
private Manager manager;
public Bank() {
manager = new Manager();
}
public void start() {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Welcome to the ATM System");
System.out.println("1. Register");
System.out.println("2. Login");
System.out.println("3. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
register(scanner);
break;
case 2:
login(scanner);
break;
case 3:
System.out.println("Thank you for using the ATM System.");
scanner.close();
return;
default:
System.out.println("Invalid option. Please try again.");
}
}
}
private void register(Scanner scanner) {
System.out.print("Enter account number: ");
String accountNumber = scanner.nextLine();
System.out.print("Enter owner name: ");
String ownerName = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
manager.createAccount(accountNumber, ownerName, password);
}
private void login(Scanner scanner) {
System.out.print("Enter account number: ");
String accountNumber = scanner.nextLine();
System.out.print("Enter password: ");
String password = scanner.nextLine();
Account account = manager.getAccount(accountNumber);
if (account != null && account.authenticate(password)) {
Client client = new Client(account);
System.out.println("Login successful.");
clientMenu(client, scanner);
} else {
System.out.println("Invalid account number or password.");
}
}
private void clientMenu(Client client, Scanner scanner) {
while (true) {
System.out.println("1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check Balance");
System.out.println("4. Logout");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
System.out.print("Enter amount to deposit: ");
double depositAmount = scanner.nextDouble();
client.deposit(depositAmount);
break;
case 2:
System.out.print("Enter amount to withdraw: ");
double withdrawAmount = scanner.nextDouble();
client.withdraw(withdrawAmount);
break;
case 3:
client.checkBalance();
break;
case 4:
System.out.println("Logged out.");
return;
default:
System.out.println("Invalid option. Please try again.");
}
}
}
public static void main(String[] args) {
Bank bank = new Bank();
bank.start();
}
}