-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBank.java
More file actions
186 lines (150 loc) · 4.3 KB
/
Bank.java
File metadata and controls
186 lines (150 loc) · 4.3 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
import java.io.*;
import java.lang.* ;
import java.util.* ;
/*Слегка запутался и были некоторые проблемы,
но вроде все нормально,возможно есть ошибки и недочеты
*/
class Person {
private String name, surname, phone ;
public Person(String name, String surname, String phone)
{
this.name = name ;
this.surname = surname ;
this.phone = phone ;
}
void setName(String name)
{
this.name = name ;
}
void setSurname(String surname)
{
this.surname = surname ;
}
void setPhone(String phone)
{
this.phone = phone ;
}
String getName()
{
return this.name ;
}
String getSurname()
{
return this.surname ;
}
String getPhone()
{
return this.phone ;
}
}
class Bill {
private Integer amount ;
public Bill(Integer amount) {
this.amount = amount;
}
public Integer getAmount() {
return amount;
}
public void setAmount(Integer amount) {
this.amount = amount;
}
}
class Account {
private Person person ;
private Bill bill ;
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
public Bill getBill() {
return bill;
}
public void setBill(Bill bill) {
this.bill = bill;
}
public Account(Person person, Bill bill) {
this.person = person;
this.bill = bill;
}
}
class Payment {
private Bill bill ;
public Payment(Bill bill) {
this.bill = bill;
}
public Bill getBill() {
return bill;
}
public void setBill(Bill bill) {
this.bill = bill;
}
}
class PaymentService {
public void pay(Account a, Payment p) {
if(a.getBill().getAmount() >= p.getBill().getAmount()) {
a.getBill().setAmount(a.getBill().getAmount()-p.getBill().getAmount());
} else {
System.out.println("Insufficient money!");
}
}
}
class Adjustment {
private Bill bill ;
}
class Deposit {
private Bill bill ;
public Deposit(Bill bill) {
this.bill = bill;
}
public Bill getBill() {
return bill;
}
public void setBill(Bill bill) {
this.bill = bill;
}
}
class DepositService {
public void deposit(Account a, Deposit d) {
a.getBill().setAmount(a.getBill().getAmount() + d.getBill().getAmount());
}
}
class TransferService {
public void transfer(Account a, Account b, int amount) {
if(a.getBill().getAmount() >= amount) {
a.getBill().setAmount(a.getBill().getAmount() - amount);
b.getBill().setAmount(b.getBill().getAmount() + amount);
} else {
System.out.println("Insufficient money!");
}
}
}
public class Bank {
public static void main(String[] args)
{
/* initialize accounts */
Account aset = new Account(new Person("Aset", "Aset", "123"), new Bill(1000-7)) ;
Account amirlan = new Account(new Person("Amirlan", "Amirlan", "88005553535"), new Bill(1000000)) ;
/* initialize services */
PaymentService paymentService = new PaymentService() ;
DepositService depositService = new DepositService() ;
TransferService transferService = new TransferService() ;
/* initialize payments */
Payment electricityPayment = new Payment(new Bill(100)) ;
Payment waterPayment = new Payment(new Bill(50)) ;
/* pay */
paymentService.pay(aset, electricityPayment);
System.out.println("Aset's Bill: " + aset.getBill().getAmount());
paymentService.pay(amirlan, waterPayment);
System.out.println("Amirlan's Bill: " + amirlan.getBill().getAmount());
/* deposit */
Deposit deposit = new Deposit(new Bill(1000000)) ;
depositService.deposit(aset, deposit);
System.out.println("Aset's Bill after deposit: " + aset.getBill().getAmount());
/* transfer */
transferService.transfer(amirlan, aset, 1000); ;
System.out.println("Aset's Bill after transfer: " + aset.getBill().getAmount());
System.out.println("Amirlan's Bill after transfer: " + amirlan.getBill().getAmount());
}
}