-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMMachine.java
More file actions
48 lines (42 loc) · 1.5 KB
/
ATMMachine.java
File metadata and controls
48 lines (42 loc) · 1.5 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
import java.util.Scanner;
public class ATMMachine {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ATM atm = new ATM();
System.out.print("Enter PIN: ");
int enteredPin = sc.nextInt();
if (!atm.authenticate(enteredPin)) {
System.out.println("Invalid PIN. Access denied.");
return;
}
int choice;
do {
System.out.println("\n--- ATM MENU ---");
System.out.println("1. Check Balance");
System.out.println("2. Deposit");
System.out.println("3. Withdraw");
System.out.println("4. Exit");
System.out.print("Choose option: ");
choice = sc.nextInt();
switch (choice) {
case 1:
atm.checkBalance();
break;
case 2:
System.out.print("Enter deposit amount: ");
atm.deposit(sc.nextDouble());
break;
case 3:
System.out.print("Enter withdraw amount: ");
atm.withdraw(sc.nextDouble());
break;
case 4:
System.out.println("Thank you for using ATM.");
break;
default:
System.out.println("Invalid option.");
}
} while (choice != 4);
sc.close();
}
}