-
Notifications
You must be signed in to change notification settings - Fork 1
/
Atm.java
132 lines (130 loc) · 4.26 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
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.util.*;
import java.text.*;
import java.util.Scanner;
public class Atm
{
private Atm(){};
public static void main(String args[])
{
Registry registry;
BankInterface stub = null;
Scanner in = null;
try
{
registry = LocateRegistry.getRegistry(null);
stub = (BankInterface) registry.lookup("BankInterface");
in = new Scanner(System.in);
}
catch (Exception e)
{
System.out.println(e);
}
// main program
try
{
while(true)
{
System.out.println("1 : check_balance");
System.out.println("2 : deposit_money");
System.out.println("3 : withdraw_money");
System.out.println("4 : transaction details between dates") ;
System.out.println("5 : transaction details") ;
System.out.println("6 : addaccount");
int type = in.nextInt() ;
if(type == 0) break ;
else if (type == 1)
{
String ac = in.next();
int b = stub.inquiry(ac);
System.out.println("Av. Balance:" + b);
}
else if(type == 2)
{
String ac = in.next();
int amount = in.nextInt();
tuple ans = stub.deposit(ac,amount);
if(ans.getId() ==0 && ans.getbalance()==0)
System.out.println("Account doesnt exist");
else
{
System.out.println("Amount deposited");
System.out.println("Transaction Id:" + ans.getId() );
System.out.println("Updated balance:" + ans.getbalance());
}
}
else if(type == 3)
{
String ac = in.next();
int amount = in.nextInt();
tuple ans = stub.withdraw(ac,amount);
if(ans.getId() ==0 && ans.getbalance()==0)
System.out.println("Account doesnt exist");
else
{
System.out.println("Amount deposited");
System.out.println("Transaction Id:" + ans.getId() );
System.out.println("Updated balance:" + ans.getbalance());
}
}
else if(type == 4)
{
String ac = in.next();
System.out.println("Enter dates in format yyyy-MM-dd");
String date1 = in.next();
String date2 = in.next();
SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
Date start_date = null;
Date end_date = null;
try
{
start_date = df.parse(date1);
end_date = df.parse(date2);
}
catch (ParseException e)
{
System.out.println(e);
}
List<Transaction> ans = stub.transaction_history(ac,start_date,end_date);
String leftAlignFormat = "| %-5s| %-30s |%n";
System.out.format("+------+--------------------------------+%n");
System.out.format("| ID | Transaction Date and Time |%n");
System.out.format("+------+--------------------------------+%n");
for(int i = 0;i < ans.size();++i)
{
System.out.format(leftAlignFormat,ans.get(i).getId() , ans.get(i).getDate()) ;
}
System.out.format("+------+--------------------------------+%n");
}
else if(type == 5)
{
String ac = in.next();
List<Transaction> ans = stub.transaction_history(ac);
String leftAlignFormat = "| %-5s| %-30s |%n";
System.out.format("+------+--------------------------------+%n");
System.out.format("| ID | Transaction Date and Time |%n");
System.out.format("+------+--------------------------------+%n");
for(int i = 0;i < ans.size();++i)
{
System.out.format(leftAlignFormat,ans.get(i).getId() , ans.get(i).getDate()) ;
}
System.out.format("+------+--------------------------------+%n");
}
else if(type == 6)
{
String name = in.next();
String ac = in.next();
String contactinfo = in.next();
String type = in.next();
int balance = in.nextInt();
stub.openaccount(name,ac,contactinfo,type,balance);
}
}
}
catch(Exception e)
{
System.out.println(e) ;
}
}
}