-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathATM.java
147 lines (128 loc) · 3.72 KB
/
ATM.java
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import java.util.Scanner;
class bank {
int PIN = 7895;
int transactions;
String transactionHistory = " ";
float bal = 100000f;
public void checkPIN() {
System.out.println("Enter your PIN for Login-:");
Scanner sc = new Scanner(System.in);
int EnterPin = sc.nextInt();
if (EnterPin == PIN) {
System.out.println("welcome Sir");
menu();
}
else{
System.out.println("Please!enter the valid PIN");
}
}
public void menu() {
System.out.println("Hey!enter your choice:-");
System.out.println("1. Enter the withdrawing amount-: ");
System.out.println("2. deposite your amount-:");
System.out.println("3. check your balance-:");
System.out.println("4. Enter the Amount to Transfer-:");
System.out.println("5. check your Transaction History-:");
System.out.println("6. Exit");
Scanner sc=new Scanner(System.in);
int choice=sc.nextInt();
if(choice==1){
withdraw();
}
else if(choice==2){
deposit();
}
else if(choice==3){
checkBalance();
}
else if(choice==4){
transfer();
}
else if(choice==5){
THistory();
}
else if(choice==6){
return;
}
else{
System.out.println("Invalid choice");
}
}
//function for withdrawing money
public void withdraw(){
System.out.println("Enter the amount to withdraw");
Scanner sc=new Scanner(System.in);
float amt=sc.nextFloat();
try{
if(bal>=amt){
transactions++;
bal-=amt;
System.out.println("\n Amount withdrawled succesfully");
String str = amt + " Rs Withdrawed\n";
transactionHistory = transactionHistory.concat(str);
}
else{
System.out.println("insufficient balance");
}
menu();
}
catch(Exception e){
}
}
//function for depositing the money
public void deposit(){
System.out.println("enter the Amount to deposite");
Scanner sc = new Scanner(System.in);
float amt=sc.nextFloat();
try{
if(amt<=100000f){
transactions++;
bal+=amt;
System.out.println("\n Amount Succesfully Deposited");
String str=amt+"\n Rs deposited";
transactionHistory=transactionHistory.concat(str);
}
menu();
}
catch(Exception e){
}
}
public void transfer(){
Scanner sc=new Scanner(System.in);
System.out.println("enter the Receiver's name");
String name=sc.nextLine();
System.out.println("enter the amount to transfer");
float amt=sc.nextFloat();
try{
if(bal>=amt){
transactions++;
bal-=amt;
System.out.println("Succesfully transfered to"+name);
String str=amt+"\n transfered to"+name;
transactionHistory=transactionHistory.concat(str);
}
menu();
}
catch(Exception e){
}
}
public void checkBalance(){
System.out.println("\n"+bal+"Rs");
menu();
}
public void THistory(){
if(transactions==0){
System.out.println("\n null");
}
else{
System.out.println("\n"+transactionHistory);
}
menu();
}
}
public class ATM {
public static void main(String[] args) {
bank b=new bank();
b.checkPIN();
}
}