-
Notifications
You must be signed in to change notification settings - Fork 0
/
atm interference.java
88 lines (75 loc) · 2.8 KB
/
atm interference.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
import java.util.Scanner;
public class atm_interference {
static class BankAccount {
private double balance;
public BankAccount(double initialBalance) {
balance = initialBalance;
}
public double getBalance() {
System.out.println("Your account balance is: $" + balance);
return balance;
}
public void deposit(double amount) {
if (amount > 0) {
balance += amount;
System.out.println("Deposited $" + amount + " successfully.");
} else {
System.out.println("Invalid deposit amount.");
}
}
public void withdrawal(double amount) {
if (amount > 0 && amount <= balance) {
balance -= amount;
System.out.println("Withdrawn $" + amount + " successfully.");
} else {
System.out.println("Invalid withdrawal amount.");
}
}
}
static class ATM {
private BankAccount userAccount;
private Scanner scanner;
public ATM(BankAccount account) {
userAccount = account;
scanner = new Scanner(System.in);
}
void displayATM() {
System.out.println("Choose one of the following options:");
System.out.println("1. Check Balance");
System.out.println("2. Deposit");
System.out.println("3. Withdraw");
System.out.println("4. Exit");
}
public void run() {
while (true) {
displayATM();
int choice = scanner.nextInt();
if (choice == 1) {
userAccount.getBalance();
} else if (choice == 2) {
System.out.println("Enter the amount to deposit:");
double amount = scanner.nextDouble();
userAccount.deposit(amount);
} else if (choice == 3) {
System.out.println("Enter the amount to withdraw:");
double amount = scanner.nextDouble();
userAccount.withdrawal(amount);
} else if (choice == 4) {
System.out.println("THANK YOU FOR USING ATM. GOODBYE!");
break;
} else {
System.out.println("Please enter a valid input.");
}
}
scanner.close();
}
}
public static void main(String[] args) {
System.out.println("__________ATM INTERFERENCE ____________");
System.out.println("Welcome to the ATM!");
double initialBalance = 10000;
BankAccount account1 = new BankAccount(initialBalance);
ATM bank = new ATM(account1);
bank.run();
}
}