-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtmMachine.java
More file actions
88 lines (80 loc) · 2.1 KB
/
Copy pathAtmMachine.java
File metadata and controls
88 lines (80 loc) · 2.1 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
79
80
81
82
83
84
85
86
87
88
package ATM_MACHINE;
import java.util.*;
class ATM
{
float Balance;
int PIN=1234;
public void checkpin()
{
System.out.println("Enter your pin: ");
Scanner sc=new Scanner(System.in);
int EnteredPin=sc.nextInt();
if(EnteredPin==PIN)
{
menu();
}
else {
System.out.println("Enter a valid pin : ");
checkpin();
}
}
public void menu()
{
System.out.println("Enter your choice- ");
System.out.println("1. Check A/C balance :");
System.out.println("2. Withdraw money : ");
System.out.println("3. Deposit money : ");
System.out.println("4. Exit ");
Scanner sc=new Scanner (System.in);
int opt=sc.nextInt();
if(opt==1)
{
checkBalance();
} else if (opt==2) {
withdrawMoney();
} else if (opt==3) {
depositMoney();
} else if (opt==4) {
return;
}
else {
System.out.println("Enter a valid choice");
}
}
public void checkBalance()
{
System.out.println("Balance : "+Balance);
menu();
}
public void withdrawMoney()
{
System.out.println("Enter amount to withdraw : ");
Scanner sc=new Scanner(System.in);
float amount=sc.nextFloat();
if(amount>Balance)
{
System.out.println("Insufficient amount");
}
else {
Balance=Balance-amount;
System.out.println("Money withdrawn successfully ");
}
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 AtmMachine {
public static void main(String[] args)
{
ATM obj= new ATM();
obj.checkpin();
}
}