-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
64 lines (63 loc) · 2.23 KB
/
Main.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
import java.util.Scanner;
interface ATM {
void withdraw(int amount);
void deposit(int amount);
void checkBalance();
}
class Bank implements ATM {
private int balance;
public Bank(int initialBalance) {
this.balance = initialBalance;
}
public void withdraw(int amount) {
if (balance >= amount) {
balance -= amount;
System.out.println("Please collect the money\n"); // Add \n for a new line
} else {
System.out.println("Insufficient balance\n"); // Add \n for a new line
}
}
public void deposit(int amount) {
balance += amount;
System.out.println("Your money has been deposited\n"); // Add \n for a new line
}
public void checkBalance() {
System.out.println("Balance: " + balance + "\n"); // Add \n for a new line
}
}
public class Main {
public static void main(String[] args) {
ATM bank = new Bank(100000);
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Automated Teller Machine");
System.out.println("1. Withdraw");
System.out.println("2. Deposit");
System.out.println("3. Balance");
System.out.println("4. Exit");
System.out.println("Choose the operation you want to do");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.println("Enter the amount to withdraw");
int withdrawAmount = sc.nextInt();
bank.withdraw(withdrawAmount);
break;
case 2:
System.out.println("Enter the amount to deposit");
int depositAmount = sc.nextInt();
bank.deposit(depositAmount);
break;
case 3:
bank.checkBalance();
break;
case 4:
System.exit(0);
break;
default:
System.out.println("Invalid choice. Please choose a valid option.");
break;
}
}
}
}