summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--bank-eiffel/account.e8
-rw-r--r--bank-eiffel/bank.e206
-rw-r--r--bank-eiffel/bank_store.e48
4 files changed, 226 insertions, 37 deletions
diff --git a/.gitignore b/.gitignore
index b1bee25..0df8baa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ pacman-c++/*.pb.cc
12*-build-desktop 12*-build-desktop
13.*.swp 13.*.swp
14bank-eiffel/EIFGENs 14bank-eiffel/EIFGENs
15bank-eiffel/bank.data
diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e
index 7c127ec..fe9cc3b 100644
--- a/bank-eiffel/account.e
+++ b/bank-eiffel/account.e
@@ -23,13 +23,15 @@ feature -- Access
23 23
24feature {NONE} -- Implementation 24feature {NONE} -- Implementation
25 25
26 creditline_range: TUPLE [min: like creditline; max: like creditline] 26 range: detachable TUPLE [min: REAL_64; max: REAL_64]
27
28 creditline_range: attached like range
27 -- min/max for creditline 29 -- min/max for creditline
28 30
29 interest_deposit_range: TUPLE [min: like interest_deposit; max: like interest_deposit] 31 interest_deposit_range: attached like range
30 -- min/max for interest_deposit 32 -- min/max for interest_deposit
31 33
32 interest_debit_range: TUPLE [min: like interest_debit; max: like interest_debit] 34 interest_debit_range: attached like range
33 -- min/max for interest_debit 35 -- min/max for interest_debit
34 36
35 authorized_signers: ARRAYED_SET [PERSON] 37 authorized_signers: ARRAYED_SET [PERSON]
diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e
index 1f61c6e..f9390c7 100644
--- a/bank-eiffel/bank.e
+++ b/bank-eiffel/bank.e
@@ -6,24 +6,46 @@ create
6 6
7feature {NONE} -- Implementation 7feature {NONE} -- Implementation
8 8
9 persons: ARRAYED_SET [PERSON] 9 store: BANK_STORE
10 -- Kunden
11
12 accounts: ARRAYED_SET [ACCOUNT]
13 -- Vorname
14 10
15 over: BOOLEAN 11 over: BOOLEAN
16 12
17 last_error: STRING 13 last_error: STRING
18 14
15 data_file: RAW_FILE
16
17 data_filename: STRING = "bank.data"
18
19feature {NONE} -- Initialization 19feature {NONE} -- Initialization
20 20
21 run 21 run
22 do 22 do
23 create persons.make(100) 23 create store.make(100)
24 create accounts.make(100) 24 store.ranges.account.creditline := [-1000.0, 0.0]
25 store.ranges.account.interest_deposit := [0.01, 0.04]
26 store.ranges.account.interest_debit := [0.02, 0.1]
27 store.ranges.studentaccount.creditline := [-300.0, 0.0]
28 store.ranges.studentaccount.interest_deposit := [0.02, 0.03]
29 store.ranges.studentaccount.interest_debit := [0.03, 0.06]
30 store.ranges.retireeaccount.creditline := [-300.0, 0.0]
31 store.ranges.retireeaccount.interest_deposit := [0.02, 0.03]
32 store.ranges.retireeaccount.interest_debit := [0.03, 0.06]
25 create last_error.make_empty 33 create last_error.make_empty
34
35 create data_file.make (data_filename)
36 if data_file.exists then
37 data_file.open_read
38 store ?= store.retrieved (data_file)
39 data_file.close
40 end
41
26 session 42 session
43
44 if data_file.is_creatable then
45 data_file.open_write
46 store.independent_store (data_file)
47 data_file.close
48 end
27 end 49 end
28 50
29feature -- Basic operations 51feature -- Basic operations
@@ -66,8 +88,9 @@ feature -- Basic operations
66 do 88 do
67 print_header 89 print_header
68 print ("Operations:%N") 90 print ("Operations:%N")
69 print (" p ...list/create/edit persons%N") 91 print (" r ...list/edit global ranges%N")
70 print (" a ...list/create/edit accounts%N") 92 print (" p ...list/create/edit/delete persons%N")
93 print (" a ...list/create/edit/delete accounts%N")
71 print (" q ...quit%N") 94 print (" q ...quit%N")
72 print ("%N") 95 print ("%N")
73 print_last_error 96 print_last_error
@@ -76,6 +99,8 @@ feature -- Basic operations
76 io.next_line 99 io.next_line
77 100
78 inspect io.last_character.lower 101 inspect io.last_character.lower
102 when 'r' then
103 ranges_screen
79 when 'p' then 104 when 'p' then
80 persons_screen 105 persons_screen
81 when 'a' then 106 when 'a' then
@@ -88,6 +113,92 @@ feature -- Basic operations
88 print ("%N%N") 113 print ("%N%N")
89 end 114 end
90 115
116 ranges_screen
117 local
118 back: BOOLEAN
119 do
120 from
121 until
122 back
123 loop
124 print_header
125 print ("Global Ranges:%N")
126 print (" Account:%N")
127 print_ranges(store.ranges.account)
128 print (" Student account:%N")
129 print_ranges(store.ranges.studentaccount)
130 print (" Retiree account:%N")
131 print_ranges(store.ranges.retireeaccount)
132 print ("%N")
133 print ("Operations:%N")
134 print (" a ...edit account ranges%N")
135 print (" s ...edit student account ranges%N")
136 print (" r ...edit retiree account ranges%N")
137 print (" b ...back%N")
138 print ("%N")
139 print_last_error
140 print ("Enter a command, followed by <return>: ")
141 io.read_character
142 io.next_line
143
144 inspect io.last_character
145 when 'a' then
146 edit_ranges("account", store.ranges.account)
147 when 's' then
148 edit_ranges("student account", store.ranges.studentaccount)
149 when 'r' then
150 edit_ranges("retiree account", store.ranges.retireeaccount)
151 when 'b' then
152 back := True
153 else
154 last_error := "Error: Unknown command '" + io.last_character.out + "'"
155 end
156 print ("%N%N")
157 end
158 end
159
160 print_ranges(range: like {BANK_STORE}.account_range)
161 do
162 print (" - Creditline: " + print_range(range.creditline) + "%N")
163 print (" - Interest deposit: " + print_range(range.interest_deposit) + "%N")
164 print (" - Interest debit: " + print_range(range.interest_debit) + "%N")
165 end
166
167 print_range(range: like {BANK_STORE}.range): STRING_8
168 local
169 fd: FORMAT_DOUBLE
170 do
171 create fd.make(2, 2)
172 Result := "[" + fd.formatted(range.min) + ", " + fd.formatted(range.max) + "]"
173 end
174
175 edit_ranges(type: STRING_8; range: like {BANK_STORE}.account_range)
176 do
177 print ("%N")
178 print ("Edit " + type + " range:%N")
179 edit_range("creditline", range.creditline)
180 edit_range("interest depost", range.interest_deposit)
181 edit_range("interest debit", range.interest_debit)
182 end
183
184 edit_range(type: STRING_8; range: like {BANK_STORE}.range)
185 local
186 fd: FORMAT_DOUBLE
187 do
188 create fd.make(2, 2)
189 print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ")
190 io.readline
191 if io.last_string.is_double then
192 range.min := io.last_string.to_double
193 end
194
195 print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ")
196 io.readline
197 if io.last_string.is_double then
198 range.max := io.last_string.to_double
199 end
200 end
201
91 persons_screen 202 persons_screen
92 local 203 local
93 back: BOOLEAN 204 back: BOOLEAN
@@ -138,8 +249,9 @@ feature -- Basic operations
138 print_header 249 print_header
139 print ("Operations:%N") 250 print ("Operations:%N")
140 print (" l ...list accounts%N") 251 print (" l ...list accounts%N")
141 print (" c ...create accounts%N") 252 print (" c ...create account%N")
142 print (" e ...edit accounts%N") 253 print (" e ...edit account%N")
254 print (" d ...delete account%N")
143 print (" b ...back%N") 255 print (" b ...back%N")
144 print ("%N") 256 print ("%N")
145 print_last_error 257 print_last_error
@@ -149,8 +261,10 @@ feature -- Basic operations
149 261
150 inspect io.last_character 262 inspect io.last_character
151 when 'l' then 263 when 'l' then
264 list_accounts
152 when 'c' then 265 when 'c' then
153 when 'e' then 266 when 'e' then
267 when 'd' then
154 when 'b' then 268 when 'b' then
155 back := True 269 back := True
156 else 270 else
@@ -163,20 +277,47 @@ feature -- Basic operations
163 list_persons 277 list_persons
164 do 278 do
165 print ("%N") 279 print ("%N")
166 print ("Persons: " + persons.count.out + "%N%N") 280 print ("Persons: " + store.persons.count.out + "%N%N")
167 from 281 from
168 persons.start 282 store.persons.start
169 until 283 until
170 persons.off 284 store.persons.off
171 loop 285 loop
172 print ("#" + persons.index.out + " " + persons.item.surname + ", " + persons.item.firstname) 286 print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname)
173 if attached {RETIREE} persons.item then 287 if attached {RETIREE} store.persons.item then
174 print (" (RETIREE)") 288 print (" (RETIREE)")
175 elseif attached {STUDENT} persons.item then 289 elseif attached {STUDENT} store.persons.item then
176 print (" (STUDENT)") 290 print (" (STUDENT)")
177 end 291 end
178 print ("%N") 292 print ("%N")
179 persons.forth 293 store.persons.forth
294 end
295
296 print ("%N")
297 print ("Press <return> to go back")
298 io.read_line
299 end
300
301 list_accounts
302 do
303 print ("%N")
304 print ("Accounts: " + store.accounts.count.out + "%N%N")
305 from
306 store.accounts.start
307 until
308 store.accounts.off
309 loop
310 --TODO
311 print ("#" + store.accounts.index.out + "%N")
312 print (" balance=" + store.accounts.item.balance.out + "%N")
313 print (" creditline=" + store.accounts.item.creditline.out + "%N")
314 if attached {RETIREEACCOUNT} store.accounts.item then
315 print (" (RETIREEACCOUNT)")
316 elseif attached {STUDENTACCOUNT} store.accounts.item then
317 print (" (STUDENTACCOUNT)")
318 end
319 print ("%N")
320 store.accounts.forth
180 end 321 end
181 322
182 print ("%N") 323 print ("%N")
@@ -218,14 +359,14 @@ feature -- Basic operations
218 359
219 inspect io.last_character 360 inspect io.last_character
220 when 'p' then 361 when 'p' then
221 persons.put(create {PERSON}.make(surname, firstname)) 362 store.persons.put(create {PERSON}.make(surname, firstname))
222 when 's' then 363 when 's' then
223 persons.put(create {STUDENT}.make(surname, firstname)) 364 store.persons.put(create {STUDENT}.make(surname, firstname))
224 when 'r' then 365 when 'r' then
225 persons.put(create {RETIREE}.make(surname, firstname)) 366 store.persons.put(create {RETIREE}.make(surname, firstname))
226 else 367 else
227 end 368 end
228 last_error := "Person (#" + persons.count.out + ") created successfully" 369 last_error := "Person (#" + store.persons.count.out + ") created successfully"
229 back := True 370 back := True
230 when 'b' then 371 when 'b' then
231 back := True 372 back := True
@@ -242,27 +383,24 @@ feature -- Basic operations
242 end 383 end
243 384
244 edit_person 385 edit_person
245 local
246 firstname: STRING
247 surname: STRING
248 do 386 do
249 print ("%N") 387 print ("%N")
250 print ("Enter person id (0 ...back): ") 388 print ("Enter person id (0 ...back): ")
251 io.read_integer 389 io.read_integer
252 if io.last_integer > 0 then 390 if io.last_integer > 0 then
253 if persons.valid_index (io.last_integer) then 391 if store.persons.valid_index (io.last_integer) then
254 persons.go_i_th (io.last_integer) 392 store.persons.go_i_th (io.last_integer)
255 393
256 print ("Enter surname [" + persons.item.surname + "]: ") 394 print ("Enter surname [" + store.persons.item.surname + "]: ")
257 io.readline 395 io.readline
258 if not io.last_string.is_empty then 396 if not io.last_string.is_empty then
259 persons.item.surname := io.last_string.twin 397 store.persons.item.surname := io.last_string.twin
260 end 398 end
261 399
262 print ("Enter firstname [" + persons.item.firstname + "]: ") 400 print ("Enter firstname [" + store.persons.item.firstname + "]: ")
263 io.readline 401 io.readline
264 if not io.last_string.is_empty then 402 if not io.last_string.is_empty then
265 persons.item.firstname := io.last_string.twin 403 store.persons.item.firstname := io.last_string.twin
266 end 404 end
267 else 405 else
268 last_error := "Invalid person id" 406 last_error := "Invalid person id"
@@ -276,9 +414,9 @@ feature -- Basic operations
276 print ("Enter person id (0 ...back): ") 414 print ("Enter person id (0 ...back): ")
277 io.read_integer 415 io.read_integer
278 if io.last_integer > 0 then 416 if io.last_integer > 0 then
279 if persons.valid_index (io.last_integer) then 417 if store.persons.valid_index (io.last_integer) then
280 persons.go_i_th (io.last_integer) 418 store.persons.go_i_th (io.last_integer)
281 persons.remove 419 store.persons.remove
282 last_error := "Person (#" + io.last_integer.out + ") removed successfully" 420 last_error := "Person (#" + io.last_integer.out + ") removed successfully"
283 else 421 else
284 last_error := "Invalid person id" 422 last_error := "Invalid person id"
diff --git a/bank-eiffel/bank_store.e b/bank-eiffel/bank_store.e
new file mode 100644
index 0000000..acc6f3a
--- /dev/null
+++ b/bank-eiffel/bank_store.e
@@ -0,0 +1,48 @@
1class
2 BANK_STORE
3
4inherit
5 STORABLE
6
7create
8 make
9
10feature
11
12 persons: ARRAYED_SET [PERSON]
13
14 accounts: ARRAYED_SET [ACCOUNT]
15
16 ranges: TUPLE [
17 account: attached like account_range;
18 studentaccount: attached like account_range;
19 retireeaccount: attached like account_range
20 ]
21
22feature {NONE} -- Implementation
23
24 account_range: detachable TUPLE [
25 creditline: attached like range;
26 interest_deposit: attached like range;
27 interest_debit: attached like range
28 ]
29
30 range: detachable like {ACCOUNT}.range
31
32feature {NONE} -- Initialization
33
34 make(cap: INTEGER)
35 do
36 create persons.make(cap)
37 create accounts.make(cap)
38 create ranges
39 ranges.account := new_range
40 ranges.studentaccount := new_range
41 ranges.retireeaccount := new_range
42 end
43
44 new_range: attached like account_range
45 do
46 create Result
47 end
48end