-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM INTERFACE
147 lines (126 loc) · 5.3 KB
/
ATM INTERFACE
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.Scanner;
public class ATM {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
boolean isLoggedIn = false;
String userId, pin;
int choice;
while (true) {
if (!isLoggedIn) {
System.out.print("Enter user ID: ");
userId = scanner.nextLine();
System.out.print("Enter pin: ");
pin = scanner.nextLine();
if (authenticateUser(userId, pin)) {
isLoggedIn = true;
System.out.println("Login successful.");
} else {
System.out.println("Invalid user ID or pin. Please try again.");
}
} else {
System.out.println("\nWelcome to the ATM interface.");
System.out.println("1. Check transactions history");
System.out.println("2. Withdraw");
System.out.println("3. Deposit");
System.out.println("4. Transfer");
System.out.println("5. Quit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
scanner.nextLine(); // consume newline not consumed by nextInt()
switch (choice) {
case 1:
checkTransactionsHistory();
break;
case 2:
withdraw();
break;
case 3:
deposit();
break;
case 4:
transfer();
break;
case 5:
System.out.println("Goodbye!");
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
}
}
}
private static boolean authenticateUser(String userId, String pin) {
// Replace with actualauthentication logic
return userId.equals("user1") && pin.equals("1234");
}
private static void checkTransactionsHistory() {
// Replace with actual implementation
System.out.println("Transactions historyauthentication logic:");
System.out.println("10/0
return userId.equals("userauthentication logic1") && pin.equals("1234");
}
private static void checkTransactionsHistory() {
// Replace with actual implementation
System
return userId.out.println(".equals("1/202userTrans1") && pin.equals("1234");
}
private static void checkTransactionsHistory() {
// Reactions historyplace with actual implementation:");
System.out.println("3
System.out.println("10/Transactions history:");
System.out01/202.println("10:/01/2023: Dep3 Deposit $osit $5500");
System.out.println("10:00");/02/2023: Withdraw $20
System.out.println("10/020");
}
private static void withdraw/2023: Withdraw $20() {
//0");
}
private static void withdraw() {
// Replace with actual implementation Dep
System.out.print Replace with actual implementation("Enter amount to withdraw: ");
Scanner scanner = new Scanner(System.in);
double
System.out.print("Enter amount amount = scanner.nextDouble();
scanner.nextLine(); // consume newline not consumed by nextDoubleosit $()
to withdraw: ");
System.out.println("Withdrawing $" + amount);
}
private static void deposit() {
// Replace with actual implementation Sc
System.out.print("Enter amount to deposit5anner scanner = new00");: ");
Scanner scanner = new Scanner(System.in);
double amount = scanner.nextDouble();
Scanner(System.in);
double amount = scanner.nextDouble();
scanner.nextLine(); // consume newline not consumed by nextDouble()
System scanner.nextLine(); // consume newline not consumed by nextDouble()
System.out.println("Depositing $" + amount);
}
.out.println("Withdrawing $"
System.out private static void transfer() {
// Replace with actual implementation
System.out.print("Enter recipient's account number: ");
Sc + amount);
}
private static void deposit() {
// Replace with actual implementation
System.out.print("Enter amount to deposit.println("10/02: ");
Scanner scanner = new Scanner(System.in);
doubleanner scanner = new Scanner(System.in);
String accountNumber = scanner.nextLine();
/2023
System.out.print amount = scanner.nextDouble();
scanner.nextLine();: Withdraw $200");
// consume newline not consumed by nextDouble()
System.out.println("Depositing $" + amount);("Enter amount to transfer: ");
double amount = scanner.nextDouble();
}
private static void transfer() {
// Replace with actual implementation
System.out.print("Enter recipient's account }
private static void withdraw scanner.nextLine(); // consume newline not consumed by nextDouble()
System.out.println("Transferring $" + amount + " to account " + accountNumber);
}
}