summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bank-eiffel/application.e19
-rw-r--r--bank-eiffel/bank.e269
-rw-r--r--bank-eiffel/bank.ecf14
-rw-r--r--bank-eiffel/tests/test_account.e1
4 files changed, 267 insertions, 36 deletions
diff --git a/bank-eiffel/application.e b/bank-eiffel/application.e
deleted file mode 100644
index 55b02d9..0000000
--- a/bank-eiffel/application.e
+++ /dev/null
@@ -1,19 +0,0 @@
1class
2 APPLICATION
3
4inherit
5 ARGUMENTS
6
7create
8 make
9
10feature {NONE} -- Initialization
11
12 make
13 -- Run application.
14 do
15 --| Add your code here
16 print ("Hello Eiffel World!%N")
17 end
18
19end
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
diff --git a/bank-eiffel/bank.ecf b/bank-eiffel/bank.ecf
index 1eef831..404ab84 100644
--- a/bank-eiffel/bank.ecf
+++ b/bank-eiffel/bank.ecf
@@ -1,26 +1,24 @@
1<?xml version="1.0" encoding="ISO-8859-1"?> 1<?xml version="1.0" encoding="ISO-8859-1"?>
2<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-7-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-7-0 http://www.eiffel.com/developers/xml/configuration-1-7-0.xsd" name="bank" uuid="ABD750A4-A528-4FEE-A7EA-37791A0D0F37"> 2<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-7-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-7-0 http://www.eiffel.com/developers/xml/configuration-1-7-0.xsd" name="bank" uuid="ABD750A4-A528-4FEE-A7EA-37791A0D0F37">
3 <target name="bank"> 3 <target name="bank">
4 <description>FOOP Exercise #3</description> 4 <description>Bank of FOOP</description>
5 <root class="APPLICATION" feature="make"/> 5 <root class="BANK" feature="run"/>
6 <version major="0" minor="1" release="0" build="0" product="bank"/> 6 <version major="0" minor="1" release="0" build="0" product="bank"/>
7 <option warning="true" is_attached_by_default="true" void_safety="all"> 7 <option warning="true" is_attached_by_default="true" void_safety="all">
8 <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/> 8 <assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
9 </option> 9 </option>
10 <setting name="executable_name" value="bank"/> 10 <setting name="console_application" value="true"/>
11 <precompile name="base_pre" location="$ISE_PRECOMP\base.ecf"/> 11 <precompile name="precompile" location="$ISE_PRECOMP\base.ecf"/>
12 <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/> 12 <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
13 <library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/> 13 <library name="testing" location="$ISE_LIBRARY\library\testing\testing.ecf"/>
14 <cluster name="bank" location=".\" recursive="true"> 14 <cluster name="bank" location=".\" recursive="true">
15 <class_option class="BANK" void_safety="none">
16 </class_option>
15 <file_rule> 17 <file_rule>
16 <exclude>/EIFGENs$</exclude> 18 <exclude>/EIFGENs$</exclude>
17 <exclude>/CVS$</exclude> 19 <exclude>/CVS$</exclude>
18 <exclude>/.svn$</exclude> 20 <exclude>/.svn$</exclude>
19 </file_rule> 21 </file_rule>
20 <tests name="tests" location="\home\manuel\uni\foop\bank-eiffel\tests\"/>
21 </cluster> 22 </cluster>
22 </target> 23 </target>
23 <target name="bank_dotnet" extends="bank">
24 <setting name="msil_generation" value="true"/>
25 </target>
26</system> 24</system>
diff --git a/bank-eiffel/tests/test_account.e b/bank-eiffel/tests/test_account.e
index 212ad6a..0b6ac46 100644
--- a/bank-eiffel/tests/test_account.e
+++ b/bank-eiffel/tests/test_account.e
@@ -104,7 +104,6 @@ feature -- Test routines
104 person2: PERSON 104 person2: PERSON
105 account2: ACCOUNT 105 account2: ACCOUNT
106 retry_count: INTEGER 106 retry_count: INTEGER
107 i: INTEGER
108 do 107 do
109 create person1.make("PERSON1", "PERSON1") 108 create person1.make("PERSON1", "PERSON1")
110 create person2.make("PERSON2", "PERSON2") 109 create person2.make("PERSON2", "PERSON2")