-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtm.java
More file actions
147 lines (94 loc) · 4.55 KB
/
Atm.java
File metadata and controls
147 lines (94 loc) · 4.55 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.util.ArrayList;
import java.util.Scanner;
public class Atm {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
ArrayList<Account> accounts = new ArrayList<>();
// Account[] accounts = new Account[10];
// Creates 10 accounts
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
accounts.add(new SavingsAccount(i, 100.0));
} else {
accounts.add(new CurrentAccount(i, 100.0, 50.0));
}
}
while (true) {
System.out.print("\nEnter an account id (0-9): ");
int id = input.nextInt();
while (id < 0 || id >= accounts.size()){
System.out.print("That id doesn't exist. Please enter a valid id (0-9): ");
id = input.nextInt();
}
boolean exit = false;
while (!exit) {
System.out.println("\n====================");
System.out.println(" Main Menu (Account " + id + ")");
System.out.println("====================");
System.out.println("1) Check Balance");
System.out.println("2) Withdraw");
System.out.println("3) Deposit");
System.out.println("4) Account Information");
System.out.println("5) Exit (switch account)");
System.out.print("Option: ");
int choice = input.nextInt();
Account selected = accounts.get(id);
switch (choice) {
case 1 -> {
System.out.println("\nCurrent balance: $" + String.format("%.2f", selected.getBalance()));;
}
case 2 -> {
System.out.print("\nEnter amount to withdraw: ");
double amount = input.nextDouble();
double withdrawn = selected.withdraw(amount);
System.out.println("\nWithdrawn: $" + String.format("%.2f", withdrawn));
System.out.println("New balance: $" + String.format("%.2f", selected.getBalance()));
}
case 3 -> {
System.out.print("\nEnter amount to deposit: ");
double amount = input.nextDouble();
selected.deposit(amount);
System.out.println("\nDeposit accepted.");
System.out.println("New balance: $" + String.format("%.2f", selected.getBalance()));
}
case 4 -> {
System.out.println(selected);
}
case 5 -> exit = true;
default -> System.out.println("Not a valid option!");
}
}
}
}
}
/*
if (choice == 1) {
System.out.println("\nCurrent balance: $" + selected.getBalance());
} else if (choice == 2) {
System.out.print("Enter amount to withdraw: ");
double amount = input.nextDouble();
double withdrawn = selected.withdraw(amount);
System.out.println("Withdrawn: $" + withdrawn);
System.out.println("New balance: $" + selected.getBalance());
} else if (choice == 3) {
System.out.print("Enter amount to deposit: ");
double amount = input.nextDouble();
selected.deposit(amount);
System.out.println("Deposit accepted.");
System.out.println("New balance: $" + selected.getBalance());
} else if (choice == 4) {
System.out.println("\n--- Account Info ---");
System.out.println("Account ID: " + selected.getId());
System.out.println("Balance: $" + selected.getBalance());
System.out.println("Interest Rate: " + Account.getAnnualInterestRate());
System.out.println("Date Created: " + String.valueOf(selected.getDateCreated()));
} else if (choice == 5) {
exit = true;
} else {
System.out.println("Not a valid option!");
}
}
}
}
}
*/