diff options
| author | manuel <manuel@mausz.at> | 2011-05-26 17:44:06 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-26 17:44:06 +0200 |
| commit | 2da65ceefaf84437d21e7e4a5697d57af02501d3 (patch) | |
| tree | 3f9cd42920f7f01ef07d0ab0f6557cf763cbe15a /bank-eiffel | |
| parent | ccfe458b09dd900c12b0421f19abdf9887d5b912 (diff) | |
| download | foop-2da65ceefaf84437d21e7e4a5697d57af02501d3.tar.gz foop-2da65ceefaf84437d21e7e4a5697d57af02501d3.tar.bz2 foop-2da65ceefaf84437d21e7e4a5697d57af02501d3.zip | |
more bank example stuff
last missing: edit account + account operations
Diffstat (limited to 'bank-eiffel')
| -rw-r--r-- | bank-eiffel/bank.e | 567 |
1 files changed, 469 insertions, 98 deletions
diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index f9390c7..523878b 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e | |||
| @@ -16,20 +16,23 @@ feature {NONE} -- Implementation | |||
| 16 | 16 | ||
| 17 | data_filename: STRING = "bank.data" | 17 | data_filename: STRING = "bank.data" |
| 18 | 18 | ||
| 19 | fd: FORMAT_DOUBLE | ||
| 20 | |||
| 19 | feature {NONE} -- Initialization | 21 | feature {NONE} -- Initialization |
| 20 | 22 | ||
| 21 | run | 23 | run |
| 22 | do | 24 | do |
| 25 | create fd.make(2, 2) | ||
| 23 | create store.make(100) | 26 | create store.make(100) |
| 24 | store.ranges.account.creditline := [-1000.0, 0.0] | ||
| 25 | store.ranges.account.interest_deposit := [0.01, 0.04] | 27 | store.ranges.account.interest_deposit := [0.01, 0.04] |
| 26 | store.ranges.account.interest_debit := [0.02, 0.1] | 28 | store.ranges.account.interest_debit := [0.02, 0.1] |
| 27 | store.ranges.studentaccount.creditline := [-300.0, 0.0] | 29 | store.ranges.account.creditline := [-1000.0, 0.0] |
| 28 | store.ranges.studentaccount.interest_deposit := [0.02, 0.03] | 30 | store.ranges.studentaccount.interest_deposit := [0.02, 0.03] |
| 29 | store.ranges.studentaccount.interest_debit := [0.03, 0.06] | 31 | store.ranges.studentaccount.interest_debit := [0.03, 0.06] |
| 30 | store.ranges.retireeaccount.creditline := [-300.0, 0.0] | 32 | store.ranges.studentaccount.creditline := [-300.0, 0.0] |
| 31 | store.ranges.retireeaccount.interest_deposit := [0.02, 0.03] | 33 | store.ranges.retireeaccount.interest_deposit := [0.02, 0.03] |
| 32 | store.ranges.retireeaccount.interest_debit := [0.03, 0.06] | 34 | store.ranges.retireeaccount.interest_debit := [0.03, 0.06] |
| 35 | store.ranges.retireeaccount.creditline := [-300.0, 0.0] | ||
| 33 | create last_error.make_empty | 36 | create last_error.make_empty |
| 34 | 37 | ||
| 35 | create data_file.make (data_filename) | 38 | create data_file.make (data_filename) |
| @@ -63,7 +66,7 @@ feature -- Basic operations | |||
| 63 | print_last_error | 66 | print_last_error |
| 64 | do | 67 | do |
| 65 | if not last_error.is_empty then | 68 | if not last_error.is_empty then |
| 66 | print (last_error + "%N%N") | 69 | print ("Error: " + last_error + "%N%N") |
| 67 | last_error := "" | 70 | last_error := "" |
| 68 | end | 71 | end |
| 69 | end | 72 | end |
| @@ -141,7 +144,7 @@ feature -- Basic operations | |||
| 141 | io.read_character | 144 | io.read_character |
| 142 | io.next_line | 145 | io.next_line |
| 143 | 146 | ||
| 144 | inspect io.last_character | 147 | inspect io.last_character.lower |
| 145 | when 'a' then | 148 | when 'a' then |
| 146 | edit_ranges("account", store.ranges.account) | 149 | edit_ranges("account", store.ranges.account) |
| 147 | when 's' then | 150 | when 's' then |
| @@ -159,16 +162,13 @@ feature -- Basic operations | |||
| 159 | 162 | ||
| 160 | print_ranges(range: like {BANK_STORE}.account_range) | 163 | print_ranges(range: like {BANK_STORE}.account_range) |
| 161 | do | 164 | do |
| 162 | print (" - Creditline: " + print_range(range.creditline) + "%N") | ||
| 163 | print (" - Interest deposit: " + print_range(range.interest_deposit) + "%N") | 165 | print (" - Interest deposit: " + print_range(range.interest_deposit) + "%N") |
| 164 | print (" - Interest debit: " + print_range(range.interest_debit) + "%N") | 166 | print (" - Interest debit: " + print_range(range.interest_debit) + "%N") |
| 167 | print (" - Creditline: " + print_range(range.creditline) + "%N") | ||
| 165 | end | 168 | end |
| 166 | 169 | ||
| 167 | print_range(range: like {BANK_STORE}.range): STRING_8 | 170 | print_range(range: like {BANK_STORE}.range): STRING_8 |
| 168 | local | ||
| 169 | fd: FORMAT_DOUBLE | ||
| 170 | do | 171 | do |
| 171 | create fd.make(2, 2) | ||
| 172 | Result := "[" + fd.formatted(range.min) + ", " + fd.formatted(range.max) + "]" | 172 | Result := "[" + fd.formatted(range.min) + ", " + fd.formatted(range.max) + "]" |
| 173 | end | 173 | end |
| 174 | 174 | ||
| @@ -176,16 +176,13 @@ feature -- Basic operations | |||
| 176 | do | 176 | do |
| 177 | print ("%N") | 177 | print ("%N") |
| 178 | print ("Edit " + type + " range:%N") | 178 | print ("Edit " + type + " range:%N") |
| 179 | edit_range("creditline", range.creditline) | ||
| 180 | edit_range("interest depost", range.interest_deposit) | 179 | edit_range("interest depost", range.interest_deposit) |
| 181 | edit_range("interest debit", range.interest_debit) | 180 | edit_range("interest debit", range.interest_debit) |
| 181 | edit_range("creditline", range.creditline) | ||
| 182 | end | 182 | end |
| 183 | 183 | ||
| 184 | edit_range(type: STRING_8; range: like {BANK_STORE}.range) | 184 | edit_range(type: STRING_8; range: like {BANK_STORE}.range) |
| 185 | local | ||
| 186 | fd: FORMAT_DOUBLE | ||
| 187 | do | 185 | do |
| 188 | create fd.make(2, 2) | ||
| 189 | print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") | 186 | print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") |
| 190 | io.readline | 187 | io.readline |
| 191 | if io.last_string.is_double then | 188 | if io.last_string.is_double then |
| @@ -220,9 +217,11 @@ feature -- Basic operations | |||
| 220 | io.read_character | 217 | io.read_character |
| 221 | io.next_line | 218 | io.next_line |
| 222 | 219 | ||
| 223 | inspect io.last_character | 220 | inspect io.last_character.lower |
| 224 | when 'l' then | 221 | when 'l' then |
| 225 | list_persons | 222 | list_persons |
| 223 | print ("Press <return> to go back") | ||
| 224 | io.read_line | ||
| 226 | when 'c' then | 225 | when 'c' then |
| 227 | create_persons | 226 | create_persons |
| 228 | when 'e' then | 227 | when 'e' then |
| @@ -238,9 +237,161 @@ feature -- Basic operations | |||
| 238 | end | 237 | end |
| 239 | end | 238 | end |
| 240 | 239 | ||
| 240 | list_persons | ||
| 241 | do | ||
| 242 | print ("%N") | ||
| 243 | print ("Persons: " + store.persons.count.out + "%N") | ||
| 244 | from | ||
| 245 | store.persons.start | ||
| 246 | until | ||
| 247 | store.persons.off | ||
| 248 | loop | ||
| 249 | print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname) | ||
| 250 | if attached {RETIREE} store.persons.item then | ||
| 251 | print (" (RETIREE)") | ||
| 252 | elseif attached {STUDENT} store.persons.item then | ||
| 253 | print (" (STUDENT)") | ||
| 254 | end | ||
| 255 | print ("%N") | ||
| 256 | store.persons.forth | ||
| 257 | end | ||
| 258 | print ("%N") | ||
| 259 | end | ||
| 260 | |||
| 261 | create_persons | ||
| 262 | local | ||
| 263 | back: BOOLEAN | ||
| 264 | firstname: STRING | ||
| 265 | surname: STRING | ||
| 266 | do | ||
| 267 | from | ||
| 268 | until | ||
| 269 | back | ||
| 270 | loop | ||
| 271 | print_header | ||
| 272 | print ("Operations:%N") | ||
| 273 | print (" p ...create person%N") | ||
| 274 | print (" s ...create student%N") | ||
| 275 | print (" r ...create retiree%N") | ||
| 276 | print (" b ...back%N") | ||
| 277 | print ("%N") | ||
| 278 | print_last_error | ||
| 279 | print ("Enter a command, followed by <return>: ") | ||
| 280 | io.read_character | ||
| 281 | io.next_line | ||
| 282 | |||
| 283 | inspect io.last_character.lower | ||
| 284 | when 'p', 's', 'r' then | ||
| 285 | print ("Enter surname: ") | ||
| 286 | io.readline | ||
| 287 | surname := io.last_string.twin | ||
| 288 | |||
| 289 | print ("Enter firstname: ") | ||
| 290 | io.readline | ||
| 291 | firstname := io.last_string.twin | ||
| 292 | |||
| 293 | inspect io.last_character.lower | ||
| 294 | when 'p' then | ||
| 295 | store.persons.put(create {PERSON}.make(surname, firstname)) | ||
| 296 | when 's' then | ||
| 297 | store.persons.put(create {STUDENT}.make(surname, firstname)) | ||
| 298 | when 'r' then | ||
| 299 | store.persons.put(create {RETIREE}.make(surname, firstname)) | ||
| 300 | else | ||
| 301 | end | ||
| 302 | last_error := "Person (#" + store.persons.count.out + ") created successfully" | ||
| 303 | back := True | ||
| 304 | when 'b' then | ||
| 305 | back := True | ||
| 306 | else | ||
| 307 | last_error := "Error: Unknown command '" + io.last_character.out + "'" | ||
| 308 | end | ||
| 309 | print ("%N%N") | ||
| 310 | end | ||
| 311 | rescue | ||
| 312 | if not (create {EXCEPTIONS}).is_signal then | ||
| 313 | last_error := "Exception: " + (create {EXCEPTIONS}).tag_name | ||
| 314 | retry | ||
| 315 | end | ||
| 316 | end | ||
| 317 | |||
| 318 | edit_person | ||
| 319 | local | ||
| 320 | back: BOOLEAN | ||
| 321 | num: INTEGER | ||
| 322 | do | ||
| 323 | list_persons | ||
| 324 | from | ||
| 325 | until | ||
| 326 | back | ||
| 327 | loop | ||
| 328 | print_last_error | ||
| 329 | print ("Enter person id (b ...back): ") | ||
| 330 | io.readline | ||
| 331 | io.last_string.to_lower | ||
| 332 | if io.last_string.is_integer then | ||
| 333 | num := io.last_string.to_integer | ||
| 334 | if store.persons.valid_index (num) then | ||
| 335 | store.persons.go_i_th (num) | ||
| 336 | |||
| 337 | print ("Enter surname [" + store.persons.item.surname + "]: ") | ||
| 338 | io.readline | ||
| 339 | if not io.last_string.is_empty then | ||
| 340 | store.persons.item.surname := io.last_string.twin | ||
| 341 | end | ||
| 342 | |||
| 343 | print ("Enter firstname [" + store.persons.item.firstname + "]: ") | ||
| 344 | io.readline | ||
| 345 | if not io.last_string.is_empty then | ||
| 346 | store.persons.item.firstname := io.last_string.twin | ||
| 347 | end | ||
| 348 | last_error := "Person (#" + num.out + ") edited successfully" | ||
| 349 | back := True | ||
| 350 | else | ||
| 351 | last_error := "Invalid person id" | ||
| 352 | end | ||
| 353 | elseif io.last_string.is_equal ("b") then | ||
| 354 | back := True | ||
| 355 | else | ||
| 356 | last_error := "Not a number" | ||
| 357 | end | ||
| 358 | end | ||
| 359 | end | ||
| 360 | |||
| 361 | delete_person | ||
| 362 | local | ||
| 363 | back: BOOLEAN | ||
| 364 | do | ||
| 365 | list_persons | ||
| 366 | from | ||
| 367 | until | ||
| 368 | back | ||
| 369 | loop | ||
| 370 | print_last_error | ||
| 371 | print ("Enter person id (b ...back): ") | ||
| 372 | io.readline | ||
| 373 | io.last_string.to_lower | ||
| 374 | if io.last_string.is_integer then | ||
| 375 | if store.persons.valid_index (io.last_string.to_integer) then | ||
| 376 | store.persons.go_i_th (io.last_string.to_integer) | ||
| 377 | store.persons.remove | ||
| 378 | last_error := "Person (#" + io.last_string + ") removed successfully" | ||
| 379 | back := True | ||
| 380 | else | ||
| 381 | last_error := "Invalid person id" | ||
| 382 | end | ||
| 383 | elseif io.last_string.is_equal ("b") then | ||
| 384 | back := True | ||
| 385 | else | ||
| 386 | last_error := "Not a number" | ||
| 387 | end | ||
| 388 | end | ||
| 389 | end | ||
| 390 | |||
| 241 | accounts_screen | 391 | accounts_screen |
| 242 | local | 392 | local |
| 243 | back: BOOLEAN | 393 | back: BOOLEAN |
| 394 | done: BOOLEAN | ||
| 244 | do | 395 | do |
| 245 | from | 396 | from |
| 246 | until | 397 | until |
| @@ -259,12 +410,42 @@ feature -- Basic operations | |||
| 259 | io.read_character | 410 | io.read_character |
| 260 | io.next_line | 411 | io.next_line |
| 261 | 412 | ||
| 262 | inspect io.last_character | 413 | inspect io.last_character.lower |
| 263 | when 'l' then | 414 | when 'l' then |
| 264 | list_accounts | 415 | list_accounts |
| 416 | |||
| 417 | from | ||
| 418 | done := False | ||
| 419 | until | ||
| 420 | back or done | ||
| 421 | loop | ||
| 422 | print ("Enter account id for details (b ...back): ") | ||
| 423 | io.readline | ||
| 424 | io.last_string.to_lower | ||
| 425 | if io.last_string.is_integer then | ||
| 426 | if store.accounts.valid_index (io.last_string.to_integer) then | ||
| 427 | store.accounts.go_i_th (io.last_string.to_integer) | ||
| 428 | print ("%N") | ||
| 429 | print ("Account #" + store.accounts.index.out + ":%N") | ||
| 430 | list_account_details(store.accounts.item) | ||
| 431 | print ("Press <return> to go back") | ||
| 432 | io.read_line | ||
| 433 | done := True | ||
| 434 | else | ||
| 435 | print ("Invalid account id%N%N") | ||
| 436 | end | ||
| 437 | elseif io.last_string.is_equal("b") then | ||
| 438 | done := True | ||
| 439 | else | ||
| 440 | print ("Not a number%N%N") | ||
| 441 | end | ||
| 442 | end | ||
| 265 | when 'c' then | 443 | when 'c' then |
| 444 | create_accounts | ||
| 266 | when 'e' then | 445 | when 'e' then |
| 446 | edit_accounts | ||
| 267 | when 'd' then | 447 | when 'd' then |
| 448 | delete_account | ||
| 268 | when 'b' then | 449 | when 'b' then |
| 269 | back := True | 450 | back := True |
| 270 | else | 451 | else |
| @@ -274,62 +455,82 @@ feature -- Basic operations | |||
| 274 | end | 455 | end |
| 275 | end | 456 | end |
| 276 | 457 | ||
| 277 | list_persons | 458 | list_accounts |
| 459 | local | ||
| 460 | account: ACCOUNT | ||
| 461 | person: PERSON | ||
| 278 | do | 462 | do |
| 279 | print ("%N") | 463 | print ("%N") |
| 280 | print ("Persons: " + store.persons.count.out + "%N%N") | 464 | print ("Accounts: " + store.accounts.count.out + "%N") |
| 281 | from | 465 | from |
| 282 | store.persons.start | 466 | store.accounts.start |
| 283 | until | 467 | until |
| 284 | store.persons.off | 468 | store.accounts.off |
| 285 | loop | 469 | loop |
| 286 | print ("#" + store.persons.index.out + " " + store.persons.item.surname + ", " + store.persons.item.firstname) | 470 | account := store.accounts.item |
| 287 | if attached {RETIREE} store.persons.item then | 471 | account.get_authorized_signers.linear_representation.start |
| 288 | print (" (RETIREE)") | 472 | person := account.get_authorized_signers.linear_representation.item |
| 289 | elseif attached {STUDENT} store.persons.item then | 473 | |
| 290 | print (" (STUDENT)") | 474 | print ("#" + store.accounts.index.out + " " + person.surname + ", " + person.firstname) |
| 475 | if attached {RETIREEACCOUNT} account then | ||
| 476 | print (" (RETIREE ACCOUNT)") | ||
| 477 | elseif attached {STUDENTACCOUNT} account then | ||
| 478 | print (" (STUDENT ACCOUNT)") | ||
| 291 | end | 479 | end |
| 292 | print ("%N") | 480 | print ("%N") |
| 293 | store.persons.forth | ||
| 294 | end | ||
| 295 | 481 | ||
| 482 | store.accounts.forth | ||
| 483 | end | ||
| 296 | print ("%N") | 484 | print ("%N") |
| 297 | print ("Press <return> to go back") | ||
| 298 | io.read_line | ||
| 299 | end | 485 | end |
| 300 | 486 | ||
| 301 | list_accounts | 487 | list_account_details(account: ACCOUNT) |
| 488 | local | ||
| 489 | person: PERSON | ||
| 490 | range: like {BANK_STORE}.account_range | ||
| 302 | do | 491 | do |
| 303 | print ("%N") | 492 | range := store.ranges.account |
| 304 | print ("Accounts: " + store.accounts.count.out + "%N%N") | 493 | if attached {RETIREEACCOUNT} account then |
| 494 | range := store.ranges.retireeaccount | ||
| 495 | elseif attached {STUDENTACCOUNT} account then | ||
| 496 | range := store.ranges.studentaccount | ||
| 497 | end | ||
| 498 | |||
| 499 | print (" - Balance: " + fd.formatted(account.balance) + "%N") | ||
| 500 | print (" - Interest deposit: " + fd.formatted(account.interest_deposit) + " " + print_range(range.interest_deposit) + "%N") | ||
| 501 | print (" - Interest debit: " + fd.formatted(account.interest_debit) + " " + print_range(range.interest_debit) +"%N") | ||
| 502 | print (" - Creditline: " + fd.formatted(account.creditline) + " " + print_range(range.creditline) +"%N") | ||
| 503 | print (" - Authorized signers:%N") | ||
| 305 | from | 504 | from |
| 306 | store.accounts.start | 505 | account.get_authorized_signers.linear_representation.start |
| 307 | until | 506 | until |
| 308 | store.accounts.off | 507 | account.get_authorized_signers.linear_representation.off |
| 309 | loop | 508 | loop |
| 310 | --TODO | 509 | person := account.get_authorized_signers.linear_representation.item |
| 311 | print ("#" + store.accounts.index.out + "%N") | 510 | print (" - #" + account.get_authorized_signers.linear_representation.index.out + " " + person.surname + ", " + person.firstname) |
| 312 | print (" balance=" + store.accounts.item.balance.out + "%N") | 511 | if attached {RETIREE} person then |
| 313 | print (" creditline=" + store.accounts.item.creditline.out + "%N") | 512 | print (" (RETIREE)") |
| 314 | if attached {RETIREEACCOUNT} store.accounts.item then | 513 | elseif attached {STUDENT} person then |
| 315 | print (" (RETIREEACCOUNT)") | 514 | print (" (STUDENT)") |
| 316 | elseif attached {STUDENTACCOUNT} store.accounts.item then | ||
| 317 | print (" (STUDENTACCOUNT)") | ||
| 318 | end | 515 | end |
| 319 | print ("%N") | 516 | print ("%N") |
| 320 | store.accounts.forth | 517 | account.get_authorized_signers.linear_representation.forth |
| 321 | end | 518 | end |
| 322 | 519 | ||
| 323 | print ("%N") | 520 | print (" - Type: ") |
| 324 | print ("Press <return> to go back") | 521 | if attached {RETIREEACCOUNT} account then |
| 325 | io.read_line | 522 | print ("Retiree account") |
| 523 | elseif attached {STUDENTACCOUNT} account then | ||
| 524 | print ("Student account") | ||
| 525 | else | ||
| 526 | print ("Account") | ||
| 527 | end | ||
| 528 | print ("%N%N") | ||
| 326 | end | 529 | end |
| 327 | 530 | ||
| 328 | create_persons | 531 | create_accounts |
| 329 | local | 532 | local |
| 330 | back: BOOLEAN | 533 | back: BOOLEAN |
| 331 | firstname: STRING | ||
| 332 | surname: STRING | ||
| 333 | do | 534 | do |
| 334 | from | 535 | from |
| 335 | until | 536 | until |
| @@ -337,9 +538,9 @@ feature -- Basic operations | |||
| 337 | loop | 538 | loop |
| 338 | print_header | 539 | print_header |
| 339 | print ("Operations:%N") | 540 | print ("Operations:%N") |
| 340 | print (" p ...create person%N") | 541 | print (" a ...create account%N") |
| 341 | print (" s ...create student%N") | 542 | print (" s ...create student account%N") |
| 342 | print (" r ...create retiree%N") | 543 | print (" r ...create retiree account%N") |
| 343 | print (" b ...back%N") | 544 | print (" b ...back%N") |
| 344 | print ("%N") | 545 | print ("%N") |
| 345 | print_last_error | 546 | print_last_error |
| @@ -347,27 +548,13 @@ feature -- Basic operations | |||
| 347 | io.read_character | 548 | io.read_character |
| 348 | io.next_line | 549 | io.next_line |
| 349 | 550 | ||
| 350 | inspect io.last_character | 551 | inspect io.last_character.lower |
| 351 | when 'p', 's', 'r' then | 552 | when 'a' then |
| 352 | print ("Enter surname: ") | 553 | back := create_account('a', store.ranges.account) |
| 353 | io.readline | 554 | when 's' then |
| 354 | surname := io.last_string.twin | 555 | back := create_account('s', store.ranges.studentaccount) |
| 355 | 556 | when 'r' then | |
| 356 | print ("Enter firstname: ") | 557 | back := create_account('r', store.ranges.retireeaccount) |
| 357 | io.readline | ||
| 358 | firstname := io.last_string.twin | ||
| 359 | |||
| 360 | inspect io.last_character | ||
| 361 | when 'p' then | ||
| 362 | store.persons.put(create {PERSON}.make(surname, firstname)) | ||
| 363 | when 's' then | ||
| 364 | store.persons.put(create {STUDENT}.make(surname, firstname)) | ||
| 365 | when 'r' then | ||
| 366 | store.persons.put(create {RETIREE}.make(surname, firstname)) | ||
| 367 | else | ||
| 368 | end | ||
| 369 | last_error := "Person (#" + store.persons.count.out + ") created successfully" | ||
| 370 | back := True | ||
| 371 | when 'b' then | 558 | when 'b' then |
| 372 | back := True | 559 | back := True |
| 373 | else | 560 | else |
| @@ -382,44 +569,228 @@ feature -- Basic operations | |||
| 382 | end | 569 | end |
| 383 | end | 570 | end |
| 384 | 571 | ||
| 385 | edit_person | 572 | create_account(type: CHARACTER; range: like {BANK_STORE}.account_range): BOOLEAN |
| 573 | local | ||
| 574 | back: BOOLEAN | ||
| 575 | next: BOOLEAN | ||
| 576 | interest_deposit: like {ACCOUNT}.interest_deposit | ||
| 577 | interest_debit: like {ACCOUNT}.interest_debit | ||
| 578 | creditline: like {ACCOUNT}.creditline | ||
| 386 | do | 579 | do |
| 387 | print ("%N") | 580 | Result := false |
| 388 | print ("Enter person id (0 ...back): ") | 581 | interest_deposit := (range.interest_deposit.min + range.interest_deposit.max) / 2 |
| 389 | io.read_integer | 582 | interest_debit := (range.interest_debit.min + range.interest_debit.max) / 2 |
| 390 | if io.last_integer > 0 then | 583 | creditline := (range.creditline.min + range.creditline.max) / 2 |
| 391 | if store.persons.valid_index (io.last_integer) then | ||
| 392 | store.persons.go_i_th (io.last_integer) | ||
| 393 | 584 | ||
| 394 | print ("Enter surname [" + store.persons.item.surname + "]: ") | 585 | print_last_error |
| 395 | io.readline | 586 | from |
| 396 | if not io.last_string.is_empty then | 587 | next := False |
| 397 | store.persons.item.surname := io.last_string.twin | 588 | list_persons |
| 589 | until | ||
| 590 | back or next | ||
| 591 | loop | ||
| 592 | print ("Enter person (authorized signer) id (b ...back): ") | ||
| 593 | io.readline | ||
| 594 | io.last_string.to_lower | ||
| 595 | if io.last_string.is_integer then | ||
| 596 | if store.persons.valid_index (io.last_string.to_integer) then | ||
| 597 | store.persons.go_i_th (io.last_string.to_integer) | ||
| 598 | next := True | ||
| 599 | else | ||
| 600 | print ("Invalid person id%N%N") | ||
| 398 | end | 601 | end |
| 602 | elseif io.last_string.is_equal ("b") then | ||
| 603 | back := True | ||
| 604 | else | ||
| 605 | print ("Not a number%N%N") | ||
| 606 | end | ||
| 607 | end | ||
| 399 | 608 | ||
| 400 | print ("Enter firstname [" + store.persons.item.firstname + "]: ") | 609 | from |
| 401 | io.readline | 610 | next := False |
| 402 | if not io.last_string.is_empty then | 611 | until |
| 403 | store.persons.item.firstname := io.last_string.twin | 612 | back or next |
| 613 | loop | ||
| 614 | print ("Enter interest deposit " + print_range(range.interest_deposit) + " [" + fd.formatted(interest_deposit) + "] (b ...back): ") | ||
| 615 | io.readline | ||
| 616 | io.last_string.to_lower | ||
| 617 | if io.last_string.is_empty then | ||
| 618 | next := True | ||
| 619 | elseif io.last_string.is_double then | ||
| 620 | interest_deposit := io.last_string.to_double | ||
| 621 | next := True | ||
| 622 | elseif io.last_string.is_equal ("b") then | ||
| 623 | back := True | ||
| 624 | else | ||
| 625 | print ("Invalid interest deposit number%N%N") | ||
| 626 | end | ||
| 627 | end | ||
| 628 | |||
| 629 | from | ||
| 630 | next := False | ||
| 631 | until | ||
| 632 | back or next | ||
| 633 | loop | ||
| 634 | print ("Enter interest debit " + print_range(range.interest_debit) + " [" + fd.formatted(interest_debit) + "] (b ...back):") | ||
| 635 | io.readline | ||
| 636 | io.last_string.to_lower | ||
| 637 | if io.last_string.is_empty then | ||
| 638 | next := True | ||
| 639 | elseif io.last_string.is_double then | ||
| 640 | interest_debit := io.last_string.to_double | ||
| 641 | next := True | ||
| 642 | elseif io.last_string.is_equal ("b") then | ||
| 643 | back := True | ||
| 644 | else | ||
| 645 | print ("Invalid interest debit number%N%N") | ||
| 646 | end | ||
| 647 | end | ||
| 648 | |||
| 649 | from | ||
| 650 | next := False | ||
| 651 | until | ||
| 652 | back or next | ||
| 653 | loop | ||
| 654 | print ("Enter creditline " + print_range(range.creditline) + " [" + fd.formatted(creditline) + "] (b ...back): ") | ||
| 655 | io.readline | ||
| 656 | io.last_string.to_lower | ||
| 657 | if io.last_string.is_empty then | ||
| 658 | next := True | ||
| 659 | elseif io.last_string.is_double then | ||
| 660 | creditline := io.last_string.to_double | ||
| 661 | next := True | ||
| 662 | elseif io.last_string.is_equal ("b") then | ||
| 663 | back := True | ||
| 664 | else | ||
| 665 | print ("Invalid creditline number%N%N") | ||
| 666 | end | ||
| 667 | end | ||
| 668 | |||
| 669 | if not back then | ||
| 670 | inspect type | ||
| 671 | when 'a' then | ||
| 672 | store.accounts.put(create {ACCOUNT}.make(store.persons.item, | ||
| 673 | interest_deposit, interest_debit, creditline, | ||
| 674 | range.interest_deposit, range.interest_debit, range.creditline)) | ||
| 675 | when 's' then | ||
| 676 | store.accounts.put(create {STUDENTACCOUNT}.make(store.persons.item, | ||
| 677 | interest_deposit, interest_debit, creditline, | ||
| 678 | range.interest_deposit, range.interest_debit, range.creditline)) | ||
| 679 | when 'r' then | ||
| 680 | store.accounts.put(create {RETIREEACCOUNT}.make(store.persons.item, | ||
| 681 | interest_deposit, interest_debit, creditline, | ||
| 682 | range.interest_deposit, range.interest_debit, range.creditline)) | ||
| 683 | else | ||
| 684 | end | ||
| 685 | last_error := "Account (#" + store.accounts.count.out + ") created successfully" | ||
| 686 | Result := true | ||
| 687 | back := True | ||
| 688 | end | ||
| 689 | end | ||
| 690 | |||
| 691 | edit_accounts | ||
| 692 | local | ||
| 693 | back: BOOLEAN | ||
| 694 | do | ||
| 695 | list_accounts | ||
| 696 | from | ||
| 697 | until | ||
| 698 | back | ||
| 699 | loop | ||
| 700 | print_last_error | ||
| 701 | print ("Enter account id (b ...back): ") | ||
| 702 | io.readline | ||
| 703 | io.last_string.to_lower | ||
| 704 | if io.last_string.is_integer then | ||
| 705 | if store.accounts.valid_index (io.last_string.to_integer) then | ||
| 706 | store.accounts.go_i_th (io.last_string.to_integer) | ||
| 707 | edit_account(store.accounts.index, store.accounts.item) | ||
| 708 | back := True | ||
| 709 | else | ||
| 710 | last_error := "Invalid account id" | ||
| 404 | end | 711 | end |
| 712 | elseif io.last_string.is_equal ("b") then | ||
| 713 | back := True | ||
| 405 | else | 714 | else |
| 406 | last_error := "Invalid person id" | 715 | last_error := "Not a number" |
| 407 | end | 716 | end |
| 408 | end | 717 | end |
| 409 | end | 718 | end |
| 410 | 719 | ||
| 411 | delete_person | 720 | edit_account(index: INTEGER; account: ACCOUNT) |
| 721 | local | ||
| 722 | back: BOOLEAN | ||
| 412 | do | 723 | do |
| 413 | print ("%N") | 724 | from |
| 414 | print ("Enter person id (0 ...back): ") | 725 | until |
| 415 | io.read_integer | 726 | back |
| 416 | if io.last_integer > 0 then | 727 | loop |
| 417 | if store.persons.valid_index (io.last_integer) then | 728 | print_header |
| 418 | store.persons.go_i_th (io.last_integer) | 729 | print ("Edit account #" + index.out + ":%N") |
| 419 | store.persons.remove | 730 | list_account_details (account) |
| 420 | last_error := "Person (#" + io.last_integer.out + ") removed successfully" | 731 | |
| 732 | print ("Operations:%N") | ||
| 733 | print (" 1 ...edit interest deposit%N") | ||
| 734 | print (" 2 ...edit interest debit%N") | ||
| 735 | print (" 3 ...edit creditline%N") | ||
| 736 | print (" 4 ...add authorized signer%N") | ||
| 737 | print (" 5 ...remove authorized signer%N") | ||
| 738 | print (" 6 ...deposit%N") | ||
| 739 | print (" 7 ...withdraw%N") | ||
| 740 | print (" 8 ...transfer%N") | ||
| 741 | print (" 9 ...advance%N") | ||
| 742 | print (" b ...back%N") | ||
| 743 | print ("%N") | ||
| 744 | print_last_error | ||
| 745 | print ("Enter a command, followed by <return>: ") | ||
| 746 | io.read_character | ||
| 747 | io.next_line | ||
| 748 | |||
| 749 | inspect io.last_character.lower | ||
| 750 | when '1' then | ||
| 751 | when '2' then | ||
| 752 | when '3' then | ||
| 753 | when '4' then | ||
| 754 | when '5' then | ||
| 755 | when '6' then | ||
| 756 | when '7' then | ||
| 757 | when '8' then | ||
| 758 | when '9' then | ||
| 759 | when 'b' then | ||
| 760 | back := True | ||
| 761 | else | ||
| 762 | last_error := "Error: Unknown command '" + io.last_character.out + "'" | ||
| 763 | end | ||
| 764 | print ("%N%N") | ||
| 765 | end | ||
| 766 | end | ||
| 767 | |||
| 768 | delete_account | ||
| 769 | local | ||
| 770 | back: BOOLEAN | ||
| 771 | do | ||
| 772 | list_accounts | ||
| 773 | from | ||
| 774 | until | ||
| 775 | back | ||
| 776 | loop | ||
| 777 | print_last_error | ||
| 778 | print ("Enter account id (b ...back): ") | ||
| 779 | io.readline | ||
| 780 | io.last_string.to_lower | ||
| 781 | if io.last_string.is_integer then | ||
| 782 | if store.accounts.valid_index (io.last_string.to_integer) then | ||
| 783 | store.accounts.go_i_th (io.last_string.to_integer) | ||
| 784 | store.accounts.remove | ||
| 785 | last_error := "Account (#" + io.last_string + ") removed successfully" | ||
| 786 | back := True | ||
| 787 | else | ||
| 788 | last_error := "Invalid account id" | ||
| 789 | end | ||
| 790 | elseif io.last_string.is_equal ("b") then | ||
| 791 | back := True | ||
| 421 | else | 792 | else |
| 422 | last_error := "Invalid person id" | 793 | last_error := "Not a number" |
| 423 | end | 794 | end |
| 424 | end | 795 | end |
| 425 | end | 796 | end |
