Repository navigation
Expand file tree
/
Copy pathATMoperations.java
More file actions
132 lines (128 loc) · 4.26 KB
/
Copy pathATMoperations.java
File metadata and controls
132 lines (128 loc) · 4.26 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Program to perform basic ATM operation based on user selection.
import java.util.Scanner;
public class ATMoperations
{
public static void main(String[] args)
{
int balance=10000;
int cash=5000;
int PIN=1234;
int ch=1;
int amnt, bal;
Scanner scanner = new Scanner(System.in);
while (ch==1)
{
System.out.println("Welcome to ATM");
System.out.println("Enter your PIN:");
int p=scanner.nextInt();
if(p==PIN)
{
System.out.println("\n Choose any one of the following:");
System.out.println("1. Check Balance");
System.out.println("2. Withdraw Money");
System.out.println("3. Deposit Money");
System.out.println("4. PIN Change");
System.out.println("5. Exit");
System.out.println("\n Enter your option:");
int option=scanner.nextInt();
switch (option)
{
case 1:
balanceCheck(balance);
break;
case 2:
System.out.println("Enter amount:");
amnt=scanner.nextInt();
bal=withdrawlMoney(amnt, balance,cash);
if(balance == bal)
System.out.println("Transaction failed");
else
{
System.out.println("updated balance = " + bal);
balance=bal;
}
break;
case 3:
System.out.println("Enter amount:");
amnt=scanner.nextInt();
bal=depositMoney(amnt, balance,cash);
if(balance == bal)
System.out.println("Transaction failed");
else
{
System.out.println("updated balance = " + bal);
balance=bal;
}
break;
case 4:
p=pinChange(PIN);
if(p!=PIN)
System.out.println("PIN changed successfully");
else
System.out.println("PIN change failed");
break;
case 5:
System.exit(0);
default:
System.out.println("Invalid option");
break;
}
}
System.out.println("\n Do you want to continue press 1:\n ");
ch=scanner.nextInt();
}
scanner.close();
}
public static int withdrawlMoney(int amount, int balance,int cash)
{
if(amount%100!=0)
return balance;
else if(amount<=balance)
{
if(amount<=cash)
return balance-amount;
else
return balance;
}
else
return balance;
}
public static void balanceCheck(int balance)
{
System.out.println("Your current balance is: "+balance);
}
public static int depositMoney(int amount, int balance,int cash)
{
if(amount%100!=0)
return balance;
else
return balance+amount;
}
public static int pinChange(int PIN)
{
Scanner scanner = new Scanner(System.in);
System.out.println(" Enter your current PIN number:");
int p=scanner.nextInt();
if(p==PIN)
{
System.out.println(" Enter your new PIN number:");
int p1=scanner.nextInt();
System.out.println("Confirm your new PIN number:");
int p2=scanner.nextInt();
if(p1==p2 && p1!=PIN && p1!=0)
{
int d=0;
while (p1>0)
{
d++;
p1=p1/10;
}
if(d==4)
PIN=p2;
else
return PIN;
}
}
return PIN;
}
}