- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtm.java
More file actions
Latest commit
126 lines (112 loc) · 4.39 KB
/
Copy pathAtm.java
File metadata and controls
126 lines (112 loc) · 4.39 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
importjava.io.*;
importjavax.swing.*;
importjava.util.*;
importjava.awt.event.*;
classAtmextendsJFrameimplementsActionListener {
JButtonwithdraw, deposit, balance;
JLabelwith, dep, bal, heading, accno;
JTextFieldw, d, b, a;
Atm() {
super("ATM APPLICATION");
this.withdraw = newJButton("WITHDRAW");
this.deposit = newJButton("DEPOSIT");
this.balance = newJButton("BALANCE");
this.with = newJLabel("WITHDRAW AMOUNT");
this.dep = newJLabel("DEPOSIT AMOUNT");
this.accno = newJLabel("ACCOUNT NUMBER");
this.bal = newJLabel("BALANCE");
this.heading = newJLabel("ATM");
this.w = newJTextField(10);
this.d = newJTextField(10);
this.b = newJTextField(10);
this.a = newJTextField(10);
this.add(this.withdraw);
this.add(this.deposit);
this.add(this.balance);
this.add(this.with);
this.add(this.dep);
this.add(this.accno);
this.add(this.bal);
this.add(this.heading);
this.add(this.w);
this.add(this.d);
this.add(this.b);
this.add(this.a);
this.setLayout(null);
this.heading.setBounds(20, 50, 150, 20);
this.accno.setBounds(20, 70, 150, 20);
this.a.setBounds(20, 90, 150, 20);
this.bal.setBounds(20, 110, 150, 20);
this.b.setBounds(20, 130, 150, 20);
this.dep.setBounds(20, 150, 150, 20);
this.d.setBounds(20, 170, 150, 20);
this.with.setBounds(20, 190, 150, 20);
this.w.setBounds(20, 210, 150, 20);
this.withdraw.setBounds(200, 150, 150, 50);
this.deposit.setBounds(350, 150, 150, 50);
this.balance.setBounds(500, 150, 150, 50);
this.setVisible(true);
this.setSize(500, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.withdraw.addActionListener(this);
this.deposit.addActionListener(this);
this.balance.addActionListener(this);
}
publicvoidactionPerformed(ActionEventae) {
Stringno;
doublebal = 0, amt;
Strings = ae.getActionCommand();
try {
if ((s.equals("DEPOSIT")) == true) {
no = this.a.getText();
FileReaderfin = newFileReader(no + ".txt");
amt = Double.parseDouble(this.d.getText());
Scannerfscan = newScanner(fin);
if ((fscan.hasNextDouble()) == true) {
bal = fscan.nextDouble();
}
bal = bal + amt;
this.b.setText(Double.toString(bal));
fin.close();
FileWriterfout = newFileWriter(no + ".txt");
fout.write(Double.toString(bal));
fout.close();
} elseif ((s.equals("WITHDRAW")) == true) {
no = this.a.getText();
FileReaderfin = newFileReader(no + ".txt");
amt = Double.parseDouble(this.w.getText());
Scannerfscan = newScanner(fin);
if ((fscan.hasNextDouble()) == true) {
bal = fscan.nextDouble();
}
if (bal < amt) {
thrownewException("INSUFFICIENT BALANCE");
}
bal = bal - amt;
this.b.setText(Double.toString(bal));
fin.close();
FileWriterfout = newFileWriter(no + ".txt");
fout.write(Double.toString(bal));
fout.close();
} elseif ((s.equals("BALANCE")) == true) {
no = this.a.getText();
FileReaderfin = newFileReader(no + ".txt");
Scannerfscan = newScanner(fin);
if ((fscan.hasNextDouble()) == true) {
bal = fscan.nextDouble();
}
this.b.setText(Double.toString(bal));
fin.close();
}
} catch (FileNotFoundExceptione) {
this.accno.setText("INVALID ACCNO");
} catch (IOExceptione) {
System.out.println("Exception:" + e);
} catch (Exceptione) {
this.b.setText("INSUFFICIENT BALANCE");
}
}
publicstaticvoidmain(Stringargs[]) {
Atma1 = newAtm();
}
}