Repository navigation
Expand file tree
/
Copy pathAtmSystem.java
More file actions
56 lines (50 loc) · 2.28 KB
/
Copy pathAtmSystem.java
File metadata and controls
56 lines (50 loc) · 2.28 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
import java.util.Scanner;
public class AtmSystem {
public static void main(String[] args) {
System.out.println("Please enter your balance: ");
Scanner scn = new Scanner(System.in);
double balance = scn.nextDouble();
if (balance >= 0) {
System.out.println("What would like you today? ");
System.out.println("1 To see your balance");
System.out.println("2 To withdraw cash");
System.out.println("3 To Deposit cash");
System.out.println("4 To exit");
System.out.println("Enter your choice:");
int choice = scn.nextInt();
if (choice == 1) {
System.out.println("Your current balance is: " + balance);
System.out.println("Have a nice day!");
} else if (choice == 2) {
System.out.println("Please enter the amount to withdraw:");
double withdraw = scn.nextDouble();
if (withdraw < balance && withdraw > 0) {
System.out.println("Your current balance is: " + (balance - withdraw));
System.out.println("Have a nice day!");
} else {
System.out.println("Error: Invalid withdraw amount");
System.out.println("Have a nice day!");
}
} else if (choice == 3) {
System.out.println("Please enter the amount to deposit: ");
double deposit = scn.nextDouble();
if (deposit > 0) {
System.out.println("Your current balance is: " + (balance + deposit));
System.out.println("Have a nice day!");
} else {
System.out.println("Error: Invalid deposit amount");
System.out.println("Have a nice day!");
}
} else if (choice == 4) {
System.out.println("Existing system");
System.out.println("Have a nice day!");
} else {
System.out.println("Error: Invalid choice");
System.out.println("Have a nice day!");
}
} else {
System.out.println("Error: Invalid balance");
System.out.println("Have a nice day!");
}
}
}