summaryrefslogtreecommitdiffstats
path: root/bank-eiffel/bank.e
diff options
context:
space:
mode:
Diffstat (limited to 'bank-eiffel/bank.e')
-rw-r--r--bank-eiffel/bank.e1120
1 files changed, 1112 insertions, 8 deletions
diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e
index 32d10ff..223f60f 100644
--- a/bank-eiffel/bank.e
+++ b/bank-eiffel/bank.e
@@ -1,20 +1,1124 @@
1note
2 description: "Summary description for {BANK}."
3 author: ""
4 date: "$Date$"
5 revision: "$Revision$"
6
7class 1class
8 BANK 2 BANK
9 3
10create 4create
11 make 5 run
6
7feature {NONE} -- Implementation
8
9 store: BANK_STORE
10
11 over: BOOLEAN
12
13 last_error: STRING
14
15 data_file: RAW_FILE
16
17 data_filename: STRING = "bank.data"
18
19 fd: FORMAT_DOUBLE
12 20
13feature {NONE} -- Initialization 21feature {NONE} -- Initialization
14 22
15 make 23 run
24 do
25 create fd.make(2, 2)
26 create store.make(100)
27 store.ranges.account.interest_deposit := [0.01, 0.04]
28 store.ranges.account.interest_debit := [0.02, 0.1]
29 store.ranges.account.creditline := [-1000.0, 0.0]
30 store.ranges.studentaccount.interest_deposit := [0.02, 0.03]
31 store.ranges.studentaccount.interest_debit := [0.03, 0.06]
32 store.ranges.studentaccount.creditline := [-300.0, 0.0]
33 store.ranges.retireeaccount.interest_deposit := [0.02, 0.03]
34 store.ranges.retireeaccount.interest_debit := [0.03, 0.06]
35 store.ranges.retireeaccount.creditline := [-300.0, 0.0]
36 create last_error.make_empty
37
38 create data_file.make (data_filename)
39 if data_file.exists then
40 data_file.open_read
41 store ?= store.retrieved (data_file)
42 data_file.close
43 end
44
45 session
46
47 if data_file.is_creatable then
48 data_file.open_write
49 store.independent_store (data_file)
50 data_file.close
51 end
52 end
53
54feature -- Basic operations
55
56 session
57 do
58 from
59 until
60 over
61 loop
62 main_screen
63 end
64 end
65
66 print_last_error
67 do
68 if not last_error.is_empty then
69 print (last_error + "%N%N")
70 last_error := ""
71 end
72 end
73
74 print_header
75 do
76 clear_screen
77 print ("**************************************%N")
78 print ("********* BANK of FOOP *********%N")
79 print ("**************************************%N")
80 end
81
82 clear_screen
83 do
84 io.put_character ((0x1B).to_character_8)
85 io.put_string ("[2J")
86 io.put_character ((0x1B).to_character_8)
87 io.put_string ("[H")
88 end
89
90 main_screen
91 do
92 print_header
93 print ("Operations:%N")
94 print (" r ...list/edit global ranges%N")
95 print (" p ...list/create/edit/delete persons%N")
96 print (" a ...list/create/edit/delete accounts%N")
97 print (" q ...quit%N")
98 print ("%N")
99 print_last_error
100 print ("Enter a command, followed by <return>: ")
101 io.read_character
102 io.next_line
103
104 inspect io.last_character.lower
105 when 'r' then
106 ranges_screen
107 when 'p' then
108 persons_screen
109 when 'a' then
110 accounts_screen
111 when 'q' then
112 over := True
113 else
114 last_error := "Error: Unknown command '" + io.last_character.out + "'"
115 end
116 print ("%N%N")
117 end
118
119 ranges_screen
120 local
121 back: BOOLEAN
122 do
123 from
124 until
125 back
126 loop
127 print_header
128 print ("Global Ranges:%N")
129 print (" Account:%N")
130 print_ranges(store.ranges.account)
131 print (" Student account:%N")
132 print_ranges(store.ranges.studentaccount)
133 print (" Retiree account:%N")
134 print_ranges(store.ranges.retireeaccount)
135 print ("%N")
136 print ("Operations:%N")
137 print (" a ...edit account ranges%N")
138 print (" s ...edit student account ranges%N")
139 print (" r ...edit retiree account ranges%N")
140 print (" b ...back%N")
141 print ("%N")
142 print_last_error
143 print ("Enter a command, followed by <return>: ")
144 io.read_character
145 io.next_line
146
147 inspect io.last_character.lower
148 when 'a' then
149 edit_ranges("account", store.ranges.account)
150 when 's' then
151 edit_ranges("student account", store.ranges.studentaccount)
152 when 'r' then
153 edit_ranges("retiree account", store.ranges.retireeaccount)
154 when 'b' then
155 back := True
156 else
157 last_error := "Error: Unknown command '" + io.last_character.out + "'"
158 end
159 print ("%N%N")
160 end
161 end
162
163 print_ranges(range: like {BANK_STORE}.account_range)
164 do
165 print (" - Interest deposit: " + print_range(range.interest_deposit) + "%N")
166 print (" - Interest debit: " + print_range(range.interest_debit) + "%N")
167 print (" - Creditline: " + print_range(range.creditline) + "%N")
168 end
169
170 print_range(range: like {BANK_STORE}.range): STRING_8
171 do
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("interest depost", range.interest_deposit)
180 edit_range("interest debit", range.interest_debit)
181 edit_range("creditline", range.creditline)
182 end
183
184 edit_range(type: STRING_8; range: like {BANK_STORE}.range)
185 local
186 back: BOOLEAN
187 do
188 from
189 back := False
190 until
191 back
192 loop
193 print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ")
194 io.readline
195 if io.last_string.is_double then
196 range.min := io.last_string.to_double
197 back := True
198 elseif io.last_string.is_empty then
199 back := True
200 else
201 print ("Invalid value%N")
202 end
203 end
204
205 from
206 back := False
207 until
208 back
209 loop
210 print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ")
211 io.readline
212 if io.last_string.is_double then
213 range.max := io.last_string.to_double
214 back := True
215 elseif io.last_string.is_empty then
216 back := True
217 else
218 print ("Invalid value%N")
219 end
220 end
221 end
222
223 persons_screen
224 local
225 back: BOOLEAN
226 do
227 from
228 until
229 back
230 loop
231 print_header
232 print ("Operations:%N")
233 print (" l ...list persons%N")
234 print (" c ...create person%N")
235 print (" e ...edit person%N")
236 print (" d ...delete person%N")
237 print (" b ...back%N")
238 print ("%N")
239 print_last_error
240 print ("Enter a command, followed by <return>: ")
241 io.read_character
242 io.next_line
243
244 inspect io.last_character.lower
245 when 'l' then
246 list_persons
247 print ("Press <return> to go back")
248 io.read_line
249 when 'c' then
250 create_persons
251 when 'e' then
252 edit_person
253 when 'd' then
254 delete_person
255 when 'b' then
256 back := True
257 else
258 last_error := "Error: Unknown command '" + io.last_character.out + "'"
259 end
260 print ("%N%N")
261 end
262 end
263
264 list_persons
265 do
266 print ("%N")
267 print ("Persons: " + store.persons.count.out + "%N")
268 from
269 store.persons.start
270 until
271 store.persons.off
272 loop
273 print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname)
274 if attached {RETIREE} store.persons.item then
275 print (" (RETIREE)")
276 elseif attached {STUDENT} store.persons.item then
277 print (" (STUDENT)")
278 end
279 print ("%N")
280 store.persons.forth
281 end
282 print ("%N")
283 end
284
285 create_persons
286 local
287 back: BOOLEAN
288 firstname: STRING
289 surname: STRING
290 do
291 from
292 until
293 back
294 loop
295 print_header
296 print ("Operations:%N")
297 print (" p ...create person%N")
298 print (" s ...create student%N")
299 print (" r ...create retiree%N")
300 print (" b ...back%N")
301 print ("%N")
302 print_last_error
303 print ("Enter a command, followed by <return>: ")
304 io.read_character
305 io.next_line
306
307 inspect io.last_character.lower
308 when 'p', 's', 'r' then
309 print ("Enter surname: ")
310 io.readline
311 surname := io.last_string.twin
312
313 print ("Enter firstname: ")
314 io.readline
315 firstname := io.last_string.twin
316
317 inspect io.last_character.lower
318 when 'p' then
319 store.persons.put(create {PERSON}.make(surname, firstname))
320 when 's' then
321 store.persons.put(create {STUDENT}.make(surname, firstname))
322 when 'r' then
323 store.persons.put(create {RETIREE}.make(surname, firstname))
324 else
325 end
326 last_error := "Person (#" + store.persons.count.out + ") created successfully"
327 back := True
328 when 'b' then
329 back := True
330 else
331 last_error := "Error: Unknown command '" + io.last_character.out + "'"
332 end
333 print ("%N%N")
334 end
335 rescue
336 if not (create {EXCEPTIONS}).is_signal then
337 last_error := "Exception: " + (create {EXCEPTIONS}).tag_name
338 retry
339 end
340 end
341
342 edit_person
343 local
344 back: BOOLEAN
345 num: INTEGER
346 do
347 list_persons
348 from
349 until
350 back
351 loop
352 print_last_error
353 print ("Enter person id (b ...back): ")
354 io.readline
355 io.last_string.to_lower
356 if io.last_string.is_integer then
357 num := io.last_string.to_integer
358 if store.persons.valid_index (num) then
359 store.persons.go_i_th (num)
360
361 print ("Enter surname [" + store.persons.item.surname + "]: ")
362 io.readline
363 if not io.last_string.is_empty then
364 store.persons.item.surname := io.last_string.twin
365 end
366
367 print ("Enter firstname [" + store.persons.item.firstname + "]: ")
368 io.readline
369 if not io.last_string.is_empty then
370 store.persons.item.firstname := io.last_string.twin
371 end
372 last_error := "Person (#" + num.out + ") edited successfully"
373 back := True
374 else
375 last_error := "Error: Invalid person id"
376 end
377 elseif io.last_string.is_equal ("b") then
378 back := True
379 else
380 last_error := "Error: Not a number"
381 end
382 end
383 end
384
385 delete_person
386 local
387 back: BOOLEAN
388 do
389 list_persons
390 from
391 until
392 back
393 loop
394 print_last_error
395 print ("Enter person id (b ...back): ")
396 io.readline
397 io.last_string.to_lower
398 if io.last_string.is_integer then
399 if store.persons.valid_index (io.last_string.to_integer) then
400 store.persons.go_i_th (io.last_string.to_integer)
401 store.persons.remove
402 last_error := "Person (#" + io.last_string + ") removed successfully"
403 back := True
404 else
405 last_error := "Error: Invalid person id"
406 end
407 elseif io.last_string.is_equal ("b") then
408 back := True
409 else
410 last_error := "Error: Not a number"
411 end
412 end
413 end
414
415 accounts_screen
416 local
417 back: BOOLEAN
418 done: BOOLEAN
419 do
420 from
421 until
422 back
423 loop
424 print_header
425 print ("Operations:%N")
426 print (" l ...list accounts%N")
427 print (" c ...create account%N")
428 print (" e ...edit account%N")
429 print (" d ...delete account%N")
430 print (" b ...back%N")
431 print ("%N")
432 print_last_error
433 print ("Enter a command, followed by <return>: ")
434 io.read_character
435 io.next_line
436
437 inspect io.last_character.lower
438 when 'l' then
439 list_accounts
440
441 from
442 done := False
443 until
444 back or done
445 loop
446 print ("Enter account id for details (b ...back): ")
447 io.readline
448 io.last_string.to_lower
449 if io.last_string.is_integer then
450 if store.accounts.valid_index (io.last_string.to_integer) then
451 store.accounts.go_i_th (io.last_string.to_integer)
452 print ("%N")
453 print ("Account #" + store.accounts.index.out + ":%N")
454 list_account_details(store.accounts.item)
455 print ("Press <return> to go back")
456 io.read_line
457 done := True
458 else
459 print ("Error: Invalid account id%N%N")
460 end
461 elseif io.last_string.is_equal("b") then
462 done := True
463 else
464 print ("Error: Not a number%N%N")
465 end
466 end
467 when 'c' then
468 create_accounts
469 when 'e' then
470 edit_accounts
471 when 'd' then
472 delete_account
473 when 'b' then
474 back := True
475 else
476 last_error := "Error: Unknown command '" + io.last_character.out + "'"
477 end
478 print ("%N%N")
479 end
480 end
481
482 list_accounts
483 local
484 account: ACCOUNT
485 person: PERSON
486 do
487 print ("%N")
488 print ("Accounts: " + store.accounts.count.out + "%N")
489 from
490 store.accounts.start
491 until
492 store.accounts.off
493 loop
494 account := store.accounts.item
495 account.get_authorized_signers.linear_representation.start
496 person := account.get_authorized_signers.linear_representation.item
497
498 print ("#" + store.accounts.index.out + " " + person.surname + ", " + person.firstname)
499 if attached {RETIREEACCOUNT} account then
500 print (" (RETIREE ACCOUNT)")
501 elseif attached {STUDENTACCOUNT} account then
502 print (" (STUDENT ACCOUNT)")
503 end
504 print ("%N")
505
506 store.accounts.forth
507 end
508 print ("%N")
509 end
510
511 list_account_details(account: ACCOUNT)
512 local
513 person: PERSON
514 range: like {BANK_STORE}.account_range
515 do
516 range := store.ranges.account
517 if attached {RETIREEACCOUNT} account then
518 range := store.ranges.retireeaccount
519 elseif attached {STUDENTACCOUNT} account then
520 range := store.ranges.studentaccount
521 end
522
523 print (" - Balance: " + fd.formatted(account.balance) + "%N")
524 print (" - Interest deposit: " + fd.formatted(account.interest_deposit) + " " + print_range(range.interest_deposit) + "%N")
525 print (" - Interest debit: " + fd.formatted(account.interest_debit) + " " + print_range(range.interest_debit) +"%N")
526 print (" - Creditline: " + fd.formatted(account.creditline) + " " + print_range(range.creditline) +"%N")
527 print (" - Minimum transfer amount: " + fd.formatted(account.transfer_minamount) +"%N")
528 print (" - Authorized signers:%N")
529 from
530 account.get_authorized_signers.linear_representation.start
531 until
532 account.get_authorized_signers.linear_representation.off
533 loop
534 person := account.get_authorized_signers.linear_representation.item
535 print (" - #" + account.get_authorized_signers.linear_representation.index.out + " " + person.surname + ", " + person.firstname)
536 if attached {RETIREE} person then
537 print (" (RETIREE)")
538 elseif attached {STUDENT} person then
539 print (" (STUDENT)")
540 end
541 print ("%N")
542 account.get_authorized_signers.linear_representation.forth
543 end
544
545 print (" - Type: ")
546 if attached {RETIREEACCOUNT} account then
547 print ("Retiree account")
548 elseif attached {STUDENTACCOUNT} account then
549 print ("Student account")
550 else
551 print ("Account")
552 end
553 print ("%N%N")
554 end
555
556 create_accounts
557 local
558 back: BOOLEAN
559 do
560 from
561 until
562 back
563 loop
564 print_header
565 print ("Operations:%N")
566 print (" a ...create account%N")
567 print (" s ...create student account%N")
568 print (" r ...create retiree account%N")
569 print (" b ...back%N")
570 print ("%N")
571 print_last_error
572 print ("Enter a command, followed by <return>: ")
573 io.read_character
574 io.next_line
575
576 inspect io.last_character.lower
577 when 'a' then
578 back := create_account('a', store.ranges.account)
579 when 's' then
580 back := create_account('s', store.ranges.studentaccount)
581 when 'r' then
582 back := create_account('r', store.ranges.retireeaccount)
583 when 'b' then
584 back := True
585 else
586 last_error := "Error: Unknown command '" + io.last_character.out + "'"
587 end
588 print ("%N%N")
589 end
590 rescue
591 if not (create {EXCEPTIONS}).is_signal then
592 last_error := "Exception: " + (create {EXCEPTIONS}).tag_name
593 retry
594 end
595 end
596
597 create_account(type: CHARACTER; range: like {BANK_STORE}.account_range): BOOLEAN
598 local
599 back: BOOLEAN
600 next: BOOLEAN
601 interest_deposit: like {ACCOUNT}.interest_deposit
602 interest_debit: like {ACCOUNT}.interest_debit
603 creditline: like {ACCOUNT}.creditline
604 do
605 Result := false
606 interest_deposit := (range.interest_deposit.min + range.interest_deposit.max) / 2
607 interest_debit := (range.interest_debit.min + range.interest_debit.max) / 2
608 creditline := (range.creditline.min + range.creditline.max) / 2
609
610 print_last_error
611 from
612 next := False
613 list_persons
614 until
615 back or next
616 loop
617 print ("Enter person (authorized signer) id (b ...back): ")
618 io.readline
619 io.last_string.to_lower
620 if io.last_string.is_integer then
621 if store.persons.valid_index (io.last_string.to_integer) then
622 store.persons.go_i_th (io.last_string.to_integer)
623 next := True
624 else
625 print ("Error: Invalid person id%N%N")
626 end
627 elseif io.last_string.is_equal ("b") then
628 back := True
629 else
630 print ("Error: Not a number%N%N")
631 end
632 end
633
634 from
635 next := False
636 until
637 back or next
638 loop
639 print ("Enter interest deposit " + print_range(range.interest_deposit) + " [" + fd.formatted(interest_deposit) + "] (b ...back): ")
640 io.readline
641 io.last_string.to_lower
642 if io.last_string.is_empty then
643 next := True
644 elseif io.last_string.is_double then
645 interest_deposit := io.last_string.to_double
646 next := True
647 elseif io.last_string.is_equal ("b") then
648 back := True
649 else
650 print ("Error: Invalid interest deposit number%N%N")
651 end
652 end
653
654 from
655 next := False
656 until
657 back or next
658 loop
659 print ("Enter interest debit " + print_range(range.interest_debit) + " [" + fd.formatted(interest_debit) + "] (b ...back):")
660 io.readline
661 io.last_string.to_lower
662 if io.last_string.is_empty then
663 next := True
664 elseif io.last_string.is_double then
665 interest_debit := io.last_string.to_double
666 next := True
667 elseif io.last_string.is_equal ("b") then
668 back := True
669 else
670 print ("Error: Invalid interest debit number%N%N")
671 end
672 end
673
674 from
675 next := False
676 until
677 back or next
678 loop
679 print ("Enter creditline " + print_range(range.creditline) + " [" + fd.formatted(creditline) + "] (b ...back): ")
680 io.readline
681 io.last_string.to_lower
682 if io.last_string.is_empty then
683 next := True
684 elseif io.last_string.is_double then
685 creditline := io.last_string.to_double
686 next := True
687 elseif io.last_string.is_equal ("b") then
688 back := True
689 else
690 print ("Error: Invalid creditline number%N%N")
691 end
692 end
693
694 if not back then
695 inspect type
696 when 'a' then
697 store.accounts.put(create {ACCOUNT}.make(store.persons.item,
698 interest_deposit, interest_debit, creditline,
699 range.interest_deposit, range.interest_debit, range.creditline))
700 when 's' then
701 store.accounts.put(create {STUDENTACCOUNT}.make(store.persons.item,
702 interest_deposit, interest_debit, creditline,
703 range.interest_deposit, range.interest_debit, range.creditline))
704 when 'r' then
705 store.accounts.put(create {RETIREEACCOUNT}.make(store.persons.item,
706 interest_deposit, interest_debit, creditline,
707 range.interest_deposit, range.interest_debit, range.creditline))
708 else
709 end
710 last_error := "Account (#" + store.accounts.count.out + ") created successfully"
711 Result := true
712 back := True
713 end
714 end
715
716 edit_accounts
717 local
718 back: BOOLEAN
16 do 719 do
720 list_accounts
721 from
722 until
723 back
724 loop
725 print_last_error
726 print ("Enter account id (b ...back): ")
727 io.readline
728 io.last_string.to_lower
729 if io.last_string.is_integer then
730 if store.accounts.valid_index (io.last_string.to_integer) then
731 store.accounts.go_i_th (io.last_string.to_integer)
732 edit_account(store.accounts.index, store.accounts.item)
733 back := True
734 else
735 last_error := "Error: Invalid account id"
736 end
737 elseif io.last_string.is_equal ("b") then
738 back := True
739 else
740 last_error := "Error: Not a number"
741 end
742 end
743 end
744
745 edit_account(index: INTEGER; account: ACCOUNT)
746 local
747 back: BOOLEAN
748 do
749 from
750 until
751 back
752 loop
753 print_header
754 print ("Edit account #" + index.out + ":%N")
755 list_account_details (account)
756
757 print ("Operations:%N")
758 print (" 1 ...edit interest deposit%N")
759 print (" 2 ...edit interest debit%N")
760 print (" 3 ...edit creditline%N")
761 print (" 4 ...edit minimum transfer amount%N")
762 print (" 5 ...add authorized signer%N")
763 print (" 6 ...remove authorized signer%N")
764 print (" 7 ...deposit%N")
765 print (" 8 ...withdraw%N")
766 print (" 9 ...transfer%N")
767 print (" 0 ...advance%N")
768 print (" b ...back%N")
769 print ("%N")
770 print_last_error
771 print ("Enter a command, followed by <return>: ")
772 io.read_character
773 io.next_line
774
775 inspect io.last_character.lower
776 when '1' then
777 account.interest_deposit := edit_account_detail_double("interest deposit", account.interest_deposit)
778 last_error := "Interest deposit changed successfully"
779 when '2' then
780 account.interest_debit := edit_account_detail_double("interest debit", account.interest_debit)
781 last_error := "Interest debit changed successfully"
782 when '3' then
783 account.creditline := edit_account_detail_double("creditline", account.creditline)
784 last_error := "Creditline changed successfully"
785 when '4' then
786 account.transfer_minamount := edit_account_detail_double("transfer miniumum amount", account.transfer_minamount)
787 last_error := "Transfer minimum amount changed successfully"
788 when '5' then
789 if edit_account_add_asigner (account) then
790 last_error := "Authorized signer added successfully"
791 end
792 when '6' then
793 if edit_account_remove_asigner (account) then
794 last_error := "Authorized signer removed successfully"
795 end
796 when '7' then
797 if edit_account_deposit (account) then
798 last_error := "Deposit successfully"
799 end
800 when '8' then
801 if edit_account_withdraw (account) then
802 last_error := "Widthdraw successfully"
803 end
804 when '9' then
805 if edit_account_transfer (account) then
806 last_error := "Transfer successfully"
807 end
808 when '0' then
809 account.advance
810 last_error := "Account advanced successfully"
811 when 'b' then
812 back := True
813 else
814 last_error := "Error: Unknown command '" + io.last_character.out + "'"
815 end
816 print ("%N%N")
817 end
818 rescue
819 if not (create {EXCEPTIONS}).is_signal then
820 last_error := "Exception: " + (create {EXCEPTIONS}).tag_name
821 retry
822 end
823 end
824
825 edit_account_detail_double(type: STRING_8; val: REAL_64): REAL_64
826 local
827 back: BOOLEAN
828 do
829 Result := val
830 from
831 until
832 back
833 loop
834 print ("Enter " + type + " [" + fd.formatted(val) + "]: ")
835 io.readline
836 if io.last_string.is_double then
837 Result := io.last_string.to_double
838 back := True
839 elseif io.last_string.is_empty then
840 back := True
841 else
842 print ("Error: Invalid value%N")
843 end
844 end
845 end
846
847 edit_account_add_asigner(account: ACCOUNT): BOOLEAN
848 local
849 back: BOOLEAN
850 do
851 Result := False
852 from
853 list_persons
854 until
855 back
856 loop
857 print_last_error
858 print ("Enter person (authorized signer) id (b ...back): ")
859 io.readline
860 io.last_string.to_lower
861 if io.last_string.is_integer then
862 if store.persons.valid_index (io.last_string.to_integer) then
863 store.persons.go_i_th(io.last_string.to_integer)
864 account.add_authorized_signer (store.persons.item)
865 Result := True
866 back := True
867 else
868 last_error := "Error: Invalid person id"
869 end
870 elseif io.last_string.is_equal ("b") then
871 back := True
872 else
873 last_error := "Error: Not a number"
874 end
875 end
876 end
877
878 edit_account_remove_asigner(account: ACCOUNT): BOOLEAN
879 local
880 back: BOOLEAN
881 do
882 Result := False
883 from
884 list_persons
885 until
886 back
887 loop
888 print_last_error
889 print ("Enter person (authorized signer) id (b ...back): ")
890 io.readline
891 io.last_string.to_lower
892 if io.last_string.is_integer then
893 if store.persons.valid_index (io.last_string.to_integer) then
894 store.persons.go_i_th(io.last_string.to_integer)
895 account.remove_authorized_signer (store.persons.item)
896 Result := True
897 back := True
898 else
899 last_error := "Error: Invalid person id"
900 end
901 elseif io.last_string.is_equal ("b") then
902 back := True
903 else
904 last_error := "Error: Not a number"
905 end
906 end
907 end
908
909 edit_account_deposit(account: ACCOUNT): BOOLEAN
910 local
911 back: BOOLEAN
912 amount: like {ACCOUNT}.balance
913 do
914 Result := False
915 from
916 until
917 back
918 loop
919 print_last_error
920
921 if amount = 0.0 and last_error.is_empty and not back then
922 print ("Enter deposit amount (b ...back): ")
923 io.readline
924 io.last_string.to_lower
925 if io.last_string.is_double and io.last_string.to_double > 0.0 then
926 amount := io.last_string.to_double
927 elseif io.last_string.is_equal("b") then
928 back := True
929 else
930 last_error := "Error: Invalid value"
931 end
932 end
933
934 if last_error.is_empty and not back then
935 list_persons
936 print ("Enter person (authorized signer) id (b ...back): ")
937 io.readline
938 io.last_string.to_lower
939 if io.last_string.is_integer then
940 if store.persons.valid_index (io.last_string.to_integer) then
941 store.persons.go_i_th(io.last_string.to_integer)
942 account.deposit (amount, store.persons.item)
943 Result := True
944 back := True
945 else
946 last_error := "Error: Invalid person id"
947 end
948 elseif io.last_string.is_equal ("b") then
949 back := True
950 else
951 last_error := "Error: Not a number"
952 end
953 end
954 end
955 end
956
957 edit_account_withdraw(account: ACCOUNT): BOOLEAN
958 local
959 back: BOOLEAN
960 amount: like {ACCOUNT}.balance
961 do
962 Result := False
963 from
964 until
965 back
966 loop
967 print_last_error
968
969 if amount = 0.0 and last_error.is_empty and not back then
970 print ("Enter withdraw amount (b ...back): ")
971 io.readline
972 io.last_string.to_lower
973 if io.last_string.is_double and io.last_string.to_double > 0.0 then
974 amount := io.last_string.to_double
975 elseif io.last_string.is_equal("b") then
976 back := True
977 else
978 last_error := "Error: Invalid value"
979 end
980 end
981
982 if last_error.is_empty and not back then
983 list_persons
984 print ("Enter person (authorized signer) id (b ...back): ")
985 io.readline
986 io.last_string.to_lower
987 if io.last_string.is_integer then
988 if store.persons.valid_index (io.last_string.to_integer) then
989 store.persons.go_i_th(io.last_string.to_integer)
990 account.withdraw (amount, store.persons.item)
991 Result := True
992 back := True
993 else
994 last_error := "Error: Invalid person id"
995 end
996 elseif io.last_string.is_equal ("b") then
997 back := True
998 else
999 last_error := "Error: Not a number"
1000 end
1001 end
1002 end
1003 end
1004
1005 edit_account_transfer(account: ACCOUNT): BOOLEAN
1006 local
1007 back: BOOLEAN
1008 amount: like {ACCOUNT}.balance
1009 signer: PERSON
1010 recipient: ACCOUNT
1011 do
1012 Result := False
1013 from
1014 until
1015 back
1016 loop
1017 print_last_error
1018
1019 if amount = 0.0 and last_error.is_empty and not back then
1020 print ("Enter transfer amount (b ...back): ")
1021 io.readline
1022 io.last_string.to_lower
1023 if io.last_string.is_double and io.last_string.to_double > 0.0 then
1024 amount := io.last_string.to_double
1025 elseif io.last_string.is_equal("b") then
1026 back := True
1027 else
1028 last_error := "Error: Invalid value"
1029 end
1030 end
17 1031
1032 print (signer)
1033 if signer = Void and last_error.is_empty and not back then
1034 list_persons
1035 print ("Enter person (authorized signer) id (b ...back): ")
1036 io.readline
1037 io.last_string.to_lower
1038 if io.last_string.is_integer then
1039 if store.persons.valid_index (io.last_string.to_integer) then
1040 store.persons.go_i_th(io.last_string.to_integer)
1041 signer := store.persons.item
1042 else
1043 last_error := "Error: Invalid person id"
1044 end
1045 elseif io.last_string.is_equal ("b") then
1046 back := True
1047 else
1048 last_error := "Error: Not a number"
1049 end
1050 end
1051
1052 print (recipient)
1053 if recipient = Void and last_error.is_empty and not back then
1054 list_accounts
1055 print ("Enter recipient account id (b ...back): ")
1056 io.readline
1057 io.last_string.to_lower
1058 if io.last_string.is_integer then
1059 if store.accounts.valid_index (io.last_string.to_integer) then
1060 store.accounts.go_i_th(io.last_string.to_integer)
1061 recipient := store.accounts.item
1062 else
1063 last_error := "Error: Invalid account id"
1064 end
1065 elseif io.last_string.is_equal ("b") then
1066 back := True
1067 else
1068 last_error := "Error: Not a number"
1069 end
1070 end
1071
1072 if last_error.is_empty and not back then
1073 list_persons
1074 print ("Enter person (authorized signer) id (b ...back): ")
1075 io.readline
1076 io.last_string.to_lower
1077 if io.last_string.is_integer then
1078 if store.persons.valid_index (io.last_string.to_integer) then
1079 store.persons.go_i_th(io.last_string.to_integer)
1080 account.transfer (amount, signer, recipient, store.persons.item)
1081 Result := True
1082 back := True
1083 else
1084 last_error := "Error: Invalid person id"
1085 end
1086 elseif io.last_string.is_equal ("b") then
1087 back := True
1088 else
1089 last_error := "Error: Not a number"
1090 end
1091 end
1092 end
18 end 1093 end
19 1094
1095 delete_account
1096 local
1097 back: BOOLEAN
1098 do
1099 list_accounts
1100 from
1101 until
1102 back
1103 loop
1104 print_last_error
1105 print ("Enter account id (b ...back): ")
1106 io.readline
1107 io.last_string.to_lower
1108 if io.last_string.is_integer then
1109 if store.accounts.valid_index (io.last_string.to_integer) then
1110 store.accounts.go_i_th (io.last_string.to_integer)
1111 store.accounts.remove
1112 last_error := "Account (#" + io.last_string + ") removed successfully"
1113 back := True
1114 else
1115 last_error := "Error: Invalid account id"
1116 end
1117 elseif io.last_string.is_equal ("b") then
1118 back := True
1119 else
1120 last_error := "Error: Not a number"
1121 end
1122 end
1123 end
20end 1124end