From 4c7743e63274a67136d849dea75262262221a570 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 24 May 2011 18:04:21 +0200 Subject: adding bank example app (not fully implemented yet) --- bank-eiffel/bank.e | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 261 insertions(+), 8 deletions(-) (limited to 'bank-eiffel/bank.e') diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index bad3bda..1f61c6e 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -2,34 +2,287 @@ class BANK create - make + run feature {NONE} -- Implementation - customers: ARRAYED_SET [PERSON] + persons: ARRAYED_SET [PERSON] -- Kunden accounts: ARRAYED_SET [ACCOUNT] -- Vorname + over: BOOLEAN + + last_error: STRING + feature {NONE} -- Initialization - make + run do - create customers.make(100) + create persons.make(100) create accounts.make(100) + create last_error.make_empty + session end feature -- Basic operations - get_customers: FINITE [PERSON] + session + do + from + until + over + loop + main_screen + end + end + + print_last_error do - Result := customers + if not last_error.is_empty then + print (last_error + "%N%N") + last_error := "" + end end - get_accounts: FINITE [ACCOUNT] + print_header do - Result := accounts + clear_screen + print ("**************************************%N") + print ("********* BANK of FOOP *********%N") + print ("**************************************%N") end + clear_screen + do + io.put_character ((0x1B).to_character_8) + io.put_string ("[2J") + io.put_character ((0x1B).to_character_8) + io.put_string ("[H") + end + + main_screen + do + print_header + print ("Operations:%N") + print (" p ...list/create/edit persons%N") + print (" a ...list/create/edit accounts%N") + print (" q ...quit%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character.lower + when 'p' then + persons_screen + when 'a' then + accounts_screen + when 'q' then + over := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + + persons_screen + local + back: BOOLEAN + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" l ...list persons%N") + print (" c ...create person%N") + print (" e ...edit person%N") + print (" d ...delete person%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'l' then + list_persons + when 'c' then + create_persons + when 'e' then + edit_person + when 'd' then + delete_person + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + end + + accounts_screen + local + back: BOOLEAN + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" l ...list accounts%N") + print (" c ...create accounts%N") + print (" e ...edit accounts%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'l' then + when 'c' then + when 'e' then + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + end + + list_persons + do + print ("%N") + print ("Persons: " + persons.count.out + "%N%N") + from + persons.start + until + persons.off + loop + print ("#" + persons.index.out + " " + persons.item.surname + ", " + persons.item.firstname) + if attached {RETIREE} persons.item then + print (" (RETIREE)") + elseif attached {STUDENT} persons.item then + print (" (STUDENT)") + end + print ("%N") + persons.forth + end + + print ("%N") + print ("Press to go back") + io.read_line + end + + create_persons + local + back: BOOLEAN + firstname: STRING + surname: STRING + do + from + until + back + loop + print_header + print ("Operations:%N") + print (" p ...create person%N") + print (" s ...create student%N") + print (" r ...create retiree%N") + print (" b ...back%N") + print ("%N") + print_last_error + print ("Enter a command, followed by : ") + io.read_character + io.next_line + + inspect io.last_character + when 'p', 's', 'r' then + print ("Enter surname: ") + io.readline + surname := io.last_string.twin + + print ("Enter firstname: ") + io.readline + firstname := io.last_string.twin + + inspect io.last_character + when 'p' then + persons.put(create {PERSON}.make(surname, firstname)) + when 's' then + persons.put(create {STUDENT}.make(surname, firstname)) + when 'r' then + persons.put(create {RETIREE}.make(surname, firstname)) + else + end + last_error := "Person (#" + persons.count.out + ") created successfully" + back := True + when 'b' then + back := True + else + last_error := "Error: Unknown command '" + io.last_character.out + "'" + end + print ("%N%N") + end + rescue + if not (create {EXCEPTIONS}).is_signal then + last_error := "Exception: " + (create {EXCEPTIONS}).tag_name + retry + end + end + + edit_person + local + firstname: STRING + surname: STRING + do + print ("%N") + print ("Enter person id (0 ...back): ") + io.read_integer + if io.last_integer > 0 then + if persons.valid_index (io.last_integer) then + persons.go_i_th (io.last_integer) + + print ("Enter surname [" + persons.item.surname + "]: ") + io.readline + if not io.last_string.is_empty then + persons.item.surname := io.last_string.twin + end + + print ("Enter firstname [" + persons.item.firstname + "]: ") + io.readline + if not io.last_string.is_empty then + persons.item.firstname := io.last_string.twin + end + else + last_error := "Invalid person id" + end + end + end + + delete_person + do + print ("%N") + print ("Enter person id (0 ...back): ") + io.read_integer + if io.last_integer > 0 then + if persons.valid_index (io.last_integer) then + persons.go_i_th (io.last_integer) + persons.remove + last_error := "Person (#" + io.last_integer.out + ") removed successfully" + else + last_error := "Invalid person id" + end + end + end end -- cgit v1.2.3