-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmProject.java
More file actions
78 lines (69 loc) · 1.96 KB
/
Copy pathAtmProject.java
File metadata and controls
78 lines (69 loc) · 1.96 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.*;
class ATM{
float Balance=5000;
int PIN=1234;
public void checkpin(){
System.out.print("Enter you Pin :");
Scanner sc=new Scanner(System.in);
int enteredpin=sc.nextInt();
if(enteredpin==PIN){
menu();
} else {
System.out.println("Oops Enter Invalid Pin");
menu();
}
}
public void menu(){
System.out.println("Please Enter your Choice");
System.out.println("1.Check Balance");
System.out.println("2.Withdraw");
System.out.println("3.Deposit Money");
System.out.println("4.Exit");
Scanner s=new Scanner(System.in);
int num=s.nextInt();
if(num==1){
ChekBalance();
}else if(num==2){
Withdraw();
}
else if(num==3){
DepositMoney();
}
else if(num==4){
return;
}else{
System.out.println("Please Enter a Valid Number");
}
}
public void ChekBalance(){
System.out.println("Balance:"+Balance);
menu();// again show menu
}
public void Withdraw(){
System.out.println("Enter Amount to Withdraw :");
Scanner sc=new Scanner(System.in);
float amount= sc.nextFloat();
if(amount>Balance){
System.out.println("Insufficient Balance");
} else{
Balance=Balance-amount;
System.out.println("Money Withdraw Successful");
menu();
}
}
public void DepositMoney(){
System.out.println("Enter the Amount");
Scanner sc=new Scanner(System.in);
float amount =sc.nextFloat();
Balance=Balance+amount;
System.out.println("Money Deposited Successfully");
menu();
}
}
public class AtmProject {
public static void main(String[] args) {
// Object Creation
ATM obj=new ATM();
obj.checkpin();
}
}