summaryrefslogtreecommitdiffstats
path: root/bank-eiffel/bank.e
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-05-24 18:04:21 +0200
committermanuel <manuel@mausz.at>2011-05-24 18:04:21 +0200
commit4c7743e63274a67136d849dea75262262221a570 (patch)
treefa6268093c64de7c199b35c05c2e2670e26533d7 /bank-eiffel/bank.e
parent9a787349e121be1ad9e83d4086244cd90422ee0e (diff)
downloadfoop-4c7743e63274a67136d849dea75262262221a570.tar.gz
foop-4c7743e63274a67136d849dea75262262221a570.tar.bz2
foop-4c7743e63274a67136d849dea75262262221a570.zip
adding bank example app (not fully implemented yet)
Diffstat (limited to 'bank-eiffel/bank.e')
-rw-r--r--bank-eiffel/bank.e269
1 files changed, 261 insertions, 8 deletions
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
2 BANK 2 BANK
3 3
4create 4create
5 make 5 run
6 6
7feature {NONE} -- Implementation 7feature {NONE} -- Implementation
8 8
9 customers: ARRAYED_SET [PERSON] 9 persons: ARRAYED_SET [PERSON]
10 -- Kunden 10 -- Kunden
11 11
12 accounts: ARRAYED_SET [ACCOUNT] 12 accounts: ARRAYED_SET [ACCOUNT]
13 -- Vorname 13 -- Vorname
14 14
15 over: BOOLEAN
16
17 last_error: STRING
18
15feature {NONE} -- Initialization 19feature {NONE} -- Initialization
16 20
17 make 21 run
18 do 22 do
19 create customers.make(100) 23 create persons.make(100)
20 create accounts.make(100) 24 create accounts.make(100)
25 create last_error.make_empty
26 session
21 end 27 end
22 28
23feature -- Basic operations 29feature -- Basic operations
24 30
25 get_customers: FINITE [PERSON] 31 session
32 do
33 from
34 until
35 over
36 loop
37 main_screen
38 end
39 end
40
41 print_last_error
26 do 42 do
27 Result := customers 43 if not last_error.is_empty then
44 print (last_error + "%N%N")
45 last_error := ""
46 end
28 end 47 end
29 48
30 get_accounts: FINITE [ACCOUNT] 49 print_header
31 do 50 do
32 Result := accounts 51 clear_screen
52 print ("**************************************%N")
53 print ("********* BANK of FOOP *********%N")
54 print ("**************************************%N")
33 end 55 end
34 56
57 clear_screen
58 do
59 io.put_character ((0x1B).to_character_8)
60 io.put_string ("[2J")
61 io.put_character ((0x1B).to_character_8)
62 io.put_string ("[H")
63 end
64
65 main_screen
66 do
67 print_header
68 print ("Operations:%N")
69 print (" p ...list/create/edit persons%N")
70 print (" a ...list/create/edit accounts%N")
71 print (" q ...quit%N")
72 print ("%N")
73 print_last_error
74 print ("Enter a command, followed by <return>: ")
75 io.read_character
76 io.next_line
77
78 inspect io.last_character.lower
79 when 'p' then
80 persons_screen
81 when 'a' then
82 accounts_screen
83 when 'q' then
84 over := True
85 else
86 last_error := "Error: Unknown command '" + io.last_character.out + "'"
87 end
88 print ("%N%N")
89 end
90
91 persons_screen
92 local
93 back: BOOLEAN
94 do
95 from
96 until
97 back
98 loop
99 print_header
100 print ("Operations:%N")
101 print (" l ...list persons%N")
102 print (" c ...create person%N")
103 print (" e ...edit person%N")
104 print (" d ...delete person%N")
105 print (" b ...back%N")
106 print ("%N")
107 print_last_error
108 print ("Enter a command, followed by <return>: ")
109 io.read_character
110 io.next_line
111
112 inspect io.last_character
113 when 'l' then
114 list_persons
115 when 'c' then
116 create_persons
117 when 'e' then
118 edit_person
119 when 'd' then
120 delete_person
121 when 'b' then
122 back := True
123 else
124 last_error := "Error: Unknown command '" + io.last_character.out + "'"
125 end
126 print ("%N%N")
127 end
128 end
129
130 accounts_screen
131 local
132 back: BOOLEAN
133 do
134 from
135 until
136 back
137 loop
138 print_header
139 print ("Operations:%N")
140 print (" l ...list accounts%N")
141 print (" c ...create accounts%N")
142 print (" e ...edit accounts%N")
143 print (" b ...back%N")
144 print ("%N")
145 print_last_error
146 print ("Enter a command, followed by <return>: ")
147 io.read_character
148 io.next_line
149
150 inspect io.last_character
151 when 'l' then
152 when 'c' then
153 when 'e' then
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 list_persons
164 do
165 print ("%N")
166 print ("Persons: " + persons.count.out + "%N%N")
167 from
168 persons.start
169 until
170 persons.off
171 loop
172 print ("#" + persons.index.out + " " + persons.item.surname + ", " + persons.item.firstname)
173 if attached {RETIREE} persons.item then
174 print (" (RETIREE)")
175 elseif attached {STUDENT} persons.item then
176 print (" (STUDENT)")
177 end
178 print ("%N")
179 persons.forth
180 end
181
182 print ("%N")
183 print ("Press <return> to go back")
184 io.read_line
185 end
186
187 create_persons
188 local
189 back: BOOLEAN
190 firstname: STRING
191 surname: STRING
192 do
193 from
194 until
195 back
196 loop
197 print_header
198 print ("Operations:%N")
199 print (" p ...create person%N")
200 print (" s ...create student%N")
201 print (" r ...create retiree%N")
202 print (" b ...back%N")
203 print ("%N")
204 print_last_error
205 print ("Enter a command, followed by <return>: ")
206 io.read_character
207 io.next_line
208
209 inspect io.last_character
210 when 'p', 's', 'r' then
211 print ("Enter surname: ")
212 io.readline
213 surname := io.last_string.twin
214
215 print ("Enter firstname: ")
216 io.readline
217 firstname := io.last_string.twin
218
219 inspect io.last_character
220 when 'p' then
221 persons.put(create {PERSON}.make(surname, firstname))
222 when 's' then
223 persons.put(create {STUDENT}.make(surname, firstname))
224 when 'r' then
225 persons.put(create {RETIREE}.make(surname, firstname))
226 else
227 end
228 last_error := "Person (#" + persons.count.out + ") created successfully"
229 back := True
230 when 'b' then
231 back := True
232 else
233 last_error := "Error: Unknown command '" + io.last_character.out + "'"
234 end
235 print ("%N%N")
236 end
237 rescue
238 if not (create {EXCEPTIONS}).is_signal then
239 last_error := "Exception: " + (create {EXCEPTIONS}).tag_name
240 retry
241 end
242 end
243
244 edit_person
245 local
246 firstname: STRING
247 surname: STRING
248 do
249 print ("%N")
250 print ("Enter person id (0 ...back): ")
251 io.read_integer
252 if io.last_integer > 0 then
253 if persons.valid_index (io.last_integer) then
254 persons.go_i_th (io.last_integer)
255
256 print ("Enter surname [" + persons.item.surname + "]: ")
257 io.readline
258 if not io.last_string.is_empty then
259 persons.item.surname := io.last_string.twin
260 end
261
262 print ("Enter firstname [" + persons.item.firstname + "]: ")
263 io.readline
264 if not io.last_string.is_empty then
265 persons.item.firstname := io.last_string.twin
266 end
267 else
268 last_error := "Invalid person id"
269 end
270 end
271 end
272
273 delete_person
274 do
275 print ("%N")
276 print ("Enter person id (0 ...back): ")
277 io.read_integer
278 if io.last_integer > 0 then
279 if persons.valid_index (io.last_integer) then
280 persons.go_i_th (io.last_integer)
281 persons.remove
282 last_error := "Person (#" + io.last_integer.out + ") removed successfully"
283 else
284 last_error := "Invalid person id"
285 end
286 end
287 end
35end 288end