-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient
More file actions
194 lines (125 loc) · 3.8 KB
/
Client
File metadata and controls
194 lines (125 loc) · 3.8 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package bank_project;
import java.util.ArrayList;
import java.util.Arrays;
public abstract class Client {
private int id;
private String name;
private float balance;
private ArrayList<Account> accounts =new ArrayList<Account>();
protected float commissionRate ;
protected float interestRate ;
public Client (int id,String name,float balance ) {
this.id=id;
this.name=name;
this.balance=balance;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getBalance() {
return balance;
}
public void setBalance(float balance) {
this.balance=balance;
}
public ArrayList<Account> getAccounts() {
return accounts;
}
public void addAccount(Account a){
accounts.add(a);
Log l = new Log(System.currentTimeMillis(),id,name,balance);
Logger Logger = new Logger("aaa");
Logger.log(l);
}
public void removeAccount(Account a){
for(int i=0;i<accounts.size();i++){
if(accounts.get(i)!=null&&accounts.get(i).equals(a)){
balance= balance+ ((Account)accounts.get(i)).getBalance();
Log l=new Log(System.currentTimeMillis(),a.getId(),"Account " +((Account)accounts.get(i)).getId()+ " was closed by client",((Account)accounts.get(i)).getBalance());
accounts.remove(a);
Logger.log(l);
return;
}
}
}
public void autoUpdateAccounts(){
for(Object a:accounts){
if(a!=null){
((Account)a).setBalance(((Account)a).getBalance()+0);
}
}
}
public void deposit(float ammount) { //להפקיד
balance=balance+ammount;
}
public void withdraw(float ammount)throws withdrawException{
float com=commissionRate*ammount/100;
if(balance-(ammount+com)>0){
System.out.println("11111");
System.out.println(balance);
balance=balance-(ammount+com);
System.out.println(balance);
Bank.addCommission(com);
}
else {
System.out.println("2222");
throw new withdrawException ("no money",this.id,this.balance,ammount);
}
}
public float getFortune(){
float total=0;
for(Account a:accounts){
if(a!=null){
total=total+ a.getBalance();
}
}
return total;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((accounts == null) ? 0 : accounts.hashCode());
result = prime * result + Float.floatToIntBits(balance);
result = prime * result + Float.floatToIntBits(commissionRate);
result = prime * result + id;
result = prime * result + Float.floatToIntBits(interestRate);
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass())return false;
Client other = (Client) obj;
if (accounts == null) {
if (other.accounts != null) return false;
} else if (!accounts.equals(other.accounts))
return false;
if (Float.floatToIntBits(balance) != Float.floatToIntBits(other.balance))
return false;
if (Float.floatToIntBits(commissionRate) != Float.floatToIntBits(other.commissionRate))
return false;
if (id != other.id)
return false;
if (Float.floatToIntBits(interestRate) != Float.floatToIntBits(other.interestRate))
return false;
if (name == null) {
if (other.name != null) return false;
} else if (!name.equals(other.name)) return false;
return true;
}
// public boolean equals(Object obj) {/// Ask Kobi
// if(obj!=null && obj instanceof Client && ((Client)obj).getId()==id && ((Client)obj).getBalance()==this.balance){
// return true;
// }
// return false;
//}
}