-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtm.java
More file actions
47 lines (38 loc) · 1.54 KB
/
Atm.java
File metadata and controls
47 lines (38 loc) · 1.54 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
import java.util.Scanner;
public class ATM {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double balance = 1000.00;
int choice = 0;
System.out.println("Welcome to the ATM!");
while (choice != 4) {
System.out.println("\n1. Deposit");
System.out.println("2. Withdraw");
System.out.println("3. Check Balance");
System.out.println("4. Exit");
System.out.print("Choose an option: ");
choice = scanner.nextInt();
if (choice == 1) {
System.out.print("Enter deposit amount: #");
double amount = scanner.nextDouble();
balance += amount;
System.out.println("Deposited. New balance: #" + balance);
} else if (choice == 2) {
System.out.print("Enter withdrawal amount: #");
double amount = scanner.nextDouble();
if (amount > balance) {
System.out.println("Insufficient funds!");
} else {
balance -= amount;
System.out.println("Withdrawn. New balance: #" + balance);
}
} else if (choice == 3) {
System.out.println("Your balance is: #" + balance);
} else if (choice == 4) {
System.out.println("Thank you! Goodbye.");
} else {
System.out.println("Invalid option. Try again.");
}
}
}
}