-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThis is simple console-based mini Project : ATM
88 lines (77 loc) · 2.7 KB
/
This is simple console-based mini Project : ATM
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 {
static String userID = "sarthak3456";
static String userPIN = "4321";
static double balance = 1000.0;
public ATM() {
}
public static void main(String[] var0) {
Scanner var1 = new Scanner(System.in);
System.out.println("Enter User ID: ");
String var2 = var1.nextLine();
System.out.println("Enter PIN: ");
String var3 = var1.nextLine();
if (validateUser(var2, var3)) {
System.out.println("Login Successful!");
int var4;
do {
System.out.println("\nATM Menu:");
System.out.println("1. Check Balance");
System.out.println("2. Deposit Money");
System.out.println("3. Withdraw Money");
System.out.println("4. Quit");
System.out.print("Choose an option by choosing number: ");
var4 = var1.nextInt();
switch (var4) {
case 1:
checkBalance();
break;
case 2:
depositMoney();
break;
case 3:
withdrawMoney();
break;
case 4:
System.out.println("Thank you for using the ATM. Goodbye!");
break;
default:
System.out.println("Invalid option, please try again.");
}
} while(var4 != 4);
} else {
System.out.println("Invalid User ID or PIN.");
}
var1.close();
}
public static boolean validateUser(String var0, String var1) {
return userID.equals(var0) && userPIN.equals(var1);
}
public static void checkBalance() {
System.out.println("\nYour current balance is: Rs" + balance);
}
public static void depositMoney() {
Scanner var0 = new Scanner(System.in);
System.out.print("\nEnter amount to deposit: ");
double var1 = var0.nextDouble();
if (var1 <= 0.0) {
System.out.println("Please enter a valid amount.");
} else {
balance += var1;
System.out.println("Successfully deposited $" + var1 + ". Your new balance is: Rs" + balance);
}
}
public static void withdrawMoney() {
Scanner var0 = new Scanner(System.in);
System.out.print("\nEnter amount to withdraw: ");
double var1 = var0.nextDouble();
if (var1 <= 0.0) {
System.out.println("Please enter a valid amount.");
} else if (var1 > balance) {
System.out.println("Insufficient balance. Try a smaller amount.");
} else {
balance -= var1;
System.out.println("Successfully withdrawn Rs" + var1 + ". Your new balance is: Rs" + balance);
}
}
}