-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATM.java
More file actions
103 lines (78 loc) · 2.45 KB
/
ATM.java
File metadata and controls
103 lines (78 loc) · 2.45 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
package Task_3;
//ATM INTERFACE
import java.util.Scanner;
public class ATM {
// The user's bank account
public BankAccount bankAccount;
// Constructor
public ATM(BankAccount bankAccount) {
this.bankAccount = bankAccount;
}
// Withdraws cash from the ATM
public void withdraw(){
System.out.println("Enter the amount you want to withdraw: ");
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
withdraw(amount);
}
// Deposits cash into the ATM
public void deposit() {
System.out.println("Enter the amount you want to deposit: ");
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
deposit(amount);
}
// Withdraws cash from the account
private void withdraw(int amount) {
if (bankAccount.getBalance() < amount) {
System.out.println("Insufficient funds");
}
else
{
bankAccount.withdraw(amount);
System.out.println("Amount Withdraw Sucessfully "+amount);
}
}
// Deposits cash into the account
private void deposit(int amount) {
bankAccount.deposit(amount);
System.out.println("Amount Deposited Sucessfully "+amount);
}
// Checks the account balance
private void checkBalance() {
System.out.println("Your account balance is: "+bankAccount.getBalance());
}
public static void main(String[] args){
BankAccount bankAccount = new BankAccount(1000);
ATM atm = new ATM(bankAccount);
int choice;
Scanner scanner = new Scanner(System.in);
do
{
System.out.println("ATM Menu");
System.out.println("1. Withdraw");
System.out.println("2. Deposit");
System.out.println("3. Check Balance");
System.out.println("4. Exit");
System.out.println("Please enter your choice: ");
choice = scanner.nextInt();
switch (choice) {
case 1:
atm.withdraw();
break;
case 2:
atm.deposit();
break;
case 3:
atm.checkBalance();
break;
case 4:
System.exit(0);
break;
default:
System.out.println("Invalid choice");
}
}while(choice!=4);
scanner.close();
}
}