From cf31e1f2788869624a9a363f7579838ddae369a2 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 26 May 2011 19:55:22 +0200 Subject: finall commit hopefully --- bank-eiffel/account.e | 13 +- bank-eiffel/bank.e | 387 +++++++++++++++++++++++++++++++++++++++---- bank-eiffel/retireeaccount.e | 13 +- bank-eiffel/studentaccount.e | 13 +- 4 files changed, 388 insertions(+), 38 deletions(-) diff --git a/bank-eiffel/account.e b/bank-eiffel/account.e index fe9cc3b..a6e30ef 100644 --- a/bank-eiffel/account.e +++ b/bank-eiffel/account.e @@ -81,16 +81,19 @@ feature -- Basic operations require an_authorized_signer_authorized: get_authorized_signers.has (an_authorized_signer) transfer_minamount_ok: an_amount >= transfer_minamount + balance_beneath_creditline: balance - an_amount >= creditline do balance := balance - an_amount ensure + balance_beneath_creditline: balance >= creditline balance_decreased: balance < old balance withdrawed: balance = old balance - an_amount - balance_beneath_creditline: balance >= creditline end transfer(an_amount: like transfer_minamount; an_authorized_signer: PERSON; an_account: like Current; another_authorized_signer: PERSON) + require + recipient_account_not_same: Current /= an_account do withdraw (an_amount, an_authorized_signer) an_account.deposit (an_amount, another_authorized_signer) @@ -107,12 +110,10 @@ feature -- Basic operations remove_authorized_signer (an_authorized_signer: PERSON) require - authorized_signers_never_empty: (get_authorized_signers.has (an_authorized_signer) - and get_authorized_signers.count >= 2) or True + authorized_signer_exists: (get_authorized_signers.has (an_authorized_signer)) + authorized_signers_not_empty: get_authorized_signers.count >= 2 do - if authorized_signers.has (an_authorized_signer) then - authorized_signers.prune (an_authorized_signer) - end + authorized_signers.prune (an_authorized_signer) ensure authorized_signers_assigned: not authorized_signers.has (an_authorized_signer) end diff --git a/bank-eiffel/bank.e b/bank-eiffel/bank.e index 523878b..223f60f 100644 --- a/bank-eiffel/bank.e +++ b/bank-eiffel/bank.e @@ -66,7 +66,7 @@ feature -- Basic operations print_last_error do if not last_error.is_empty then - print ("Error: " + last_error + "%N%N") + print (last_error + "%N%N") last_error := "" end end @@ -182,17 +182,41 @@ feature -- Basic operations end edit_range(type: STRING_8; range: like {BANK_STORE}.range) + local + back: BOOLEAN do - print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") - io.readline - if io.last_string.is_double then - range.min := io.last_string.to_double + from + back := False + until + back + loop + print ("Enter " + type + " minimum [" + fd.formatted(range.min) + "]: ") + io.readline + if io.last_string.is_double then + range.min := io.last_string.to_double + back := True + elseif io.last_string.is_empty then + back := True + else + print ("Invalid value%N") + end end - print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ") - io.readline - if io.last_string.is_double then - range.max := io.last_string.to_double + from + back := False + until + back + loop + print ("Enter " + type + " maximum [" + fd.formatted(range.max) + "]: ") + io.readline + if io.last_string.is_double then + range.max := io.last_string.to_double + back := True + elseif io.last_string.is_empty then + back := True + else + print ("Invalid value%N") + end end end @@ -348,12 +372,12 @@ feature -- Basic operations last_error := "Person (#" + num.out + ") edited successfully" back := True else - last_error := "Invalid person id" + last_error := "Error: Invalid person id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end @@ -378,12 +402,12 @@ feature -- Basic operations last_error := "Person (#" + io.last_string + ") removed successfully" back := True else - last_error := "Invalid person id" + last_error := "Error: Invalid person id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end @@ -432,12 +456,12 @@ feature -- Basic operations io.read_line done := True else - print ("Invalid account id%N%N") + print ("Error: Invalid account id%N%N") end elseif io.last_string.is_equal("b") then done := True else - print ("Not a number%N%N") + print ("Error: Not a number%N%N") end end when 'c' then @@ -500,6 +524,7 @@ feature -- Basic operations print (" - Interest deposit: " + fd.formatted(account.interest_deposit) + " " + print_range(range.interest_deposit) + "%N") print (" - Interest debit: " + fd.formatted(account.interest_debit) + " " + print_range(range.interest_debit) +"%N") print (" - Creditline: " + fd.formatted(account.creditline) + " " + print_range(range.creditline) +"%N") + print (" - Minimum transfer amount: " + fd.formatted(account.transfer_minamount) +"%N") print (" - Authorized signers:%N") from account.get_authorized_signers.linear_representation.start @@ -597,12 +622,12 @@ feature -- Basic operations store.persons.go_i_th (io.last_string.to_integer) next := True else - print ("Invalid person id%N%N") + print ("Error: Invalid person id%N%N") end elseif io.last_string.is_equal ("b") then back := True else - print ("Not a number%N%N") + print ("Error: Not a number%N%N") end end @@ -622,7 +647,7 @@ feature -- Basic operations elseif io.last_string.is_equal ("b") then back := True else - print ("Invalid interest deposit number%N%N") + print ("Error: Invalid interest deposit number%N%N") end end @@ -642,7 +667,7 @@ feature -- Basic operations elseif io.last_string.is_equal ("b") then back := True else - print ("Invalid interest debit number%N%N") + print ("Error: Invalid interest debit number%N%N") end end @@ -662,7 +687,7 @@ feature -- Basic operations elseif io.last_string.is_equal ("b") then back := True else - print ("Invalid creditline number%N%N") + print ("Error: Invalid creditline number%N%N") end end @@ -707,12 +732,12 @@ feature -- Basic operations edit_account(store.accounts.index, store.accounts.item) back := True else - last_error := "Invalid account id" + last_error := "Error: Invalid account id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end @@ -733,12 +758,13 @@ feature -- Basic operations print (" 1 ...edit interest deposit%N") print (" 2 ...edit interest debit%N") print (" 3 ...edit creditline%N") - print (" 4 ...add authorized signer%N") - print (" 5 ...remove authorized signer%N") - print (" 6 ...deposit%N") - print (" 7 ...withdraw%N") - print (" 8 ...transfer%N") - print (" 9 ...advance%N") + print (" 4 ...edit minimum transfer amount%N") + print (" 5 ...add authorized signer%N") + print (" 6 ...remove authorized signer%N") + print (" 7 ...deposit%N") + print (" 8 ...withdraw%N") + print (" 9 ...transfer%N") + print (" 0 ...advance%N") print (" b ...back%N") print ("%N") print_last_error @@ -748,14 +774,40 @@ feature -- Basic operations inspect io.last_character.lower when '1' then + account.interest_deposit := edit_account_detail_double("interest deposit", account.interest_deposit) + last_error := "Interest deposit changed successfully" when '2' then + account.interest_debit := edit_account_detail_double("interest debit", account.interest_debit) + last_error := "Interest debit changed successfully" when '3' then + account.creditline := edit_account_detail_double("creditline", account.creditline) + last_error := "Creditline changed successfully" when '4' then + account.transfer_minamount := edit_account_detail_double("transfer miniumum amount", account.transfer_minamount) + last_error := "Transfer minimum amount changed successfully" when '5' then + if edit_account_add_asigner (account) then + last_error := "Authorized signer added successfully" + end when '6' then + if edit_account_remove_asigner (account) then + last_error := "Authorized signer removed successfully" + end when '7' then + if edit_account_deposit (account) then + last_error := "Deposit successfully" + end when '8' then + if edit_account_withdraw (account) then + last_error := "Widthdraw successfully" + end when '9' then + if edit_account_transfer (account) then + last_error := "Transfer successfully" + end + when '0' then + account.advance + last_error := "Account advanced successfully" when 'b' then back := True else @@ -763,6 +815,281 @@ feature -- Basic operations end print ("%N%N") end + rescue + if not (create {EXCEPTIONS}).is_signal then + last_error := "Exception: " + (create {EXCEPTIONS}).tag_name + retry + end + end + + edit_account_detail_double(type: STRING_8; val: REAL_64): REAL_64 + local + back: BOOLEAN + do + Result := val + from + until + back + loop + print ("Enter " + type + " [" + fd.formatted(val) + "]: ") + io.readline + if io.last_string.is_double then + Result := io.last_string.to_double + back := True + elseif io.last_string.is_empty then + back := True + else + print ("Error: Invalid value%N") + end + end + end + + edit_account_add_asigner(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + do + Result := False + from + list_persons + until + back + loop + print_last_error + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.add_authorized_signer (store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + + edit_account_remove_asigner(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + do + Result := False + from + list_persons + until + back + loop + print_last_error + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.remove_authorized_signer (store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + + edit_account_deposit(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + amount: like {ACCOUNT}.balance + do + Result := False + from + until + back + loop + print_last_error + + if amount = 0.0 and last_error.is_empty and not back then + print ("Enter deposit amount (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_double and io.last_string.to_double > 0.0 then + amount := io.last_string.to_double + elseif io.last_string.is_equal("b") then + back := True + else + last_error := "Error: Invalid value" + end + end + + if last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.deposit (amount, store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + end + + edit_account_withdraw(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + amount: like {ACCOUNT}.balance + do + Result := False + from + until + back + loop + print_last_error + + if amount = 0.0 and last_error.is_empty and not back then + print ("Enter withdraw amount (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_double and io.last_string.to_double > 0.0 then + amount := io.last_string.to_double + elseif io.last_string.is_equal("b") then + back := True + else + last_error := "Error: Invalid value" + end + end + + if last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.withdraw (amount, store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end + end + + edit_account_transfer(account: ACCOUNT): BOOLEAN + local + back: BOOLEAN + amount: like {ACCOUNT}.balance + signer: PERSON + recipient: ACCOUNT + do + Result := False + from + until + back + loop + print_last_error + + if amount = 0.0 and last_error.is_empty and not back then + print ("Enter transfer amount (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_double and io.last_string.to_double > 0.0 then + amount := io.last_string.to_double + elseif io.last_string.is_equal("b") then + back := True + else + last_error := "Error: Invalid value" + end + end + + print (signer) + if signer = Void and last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + signer := store.persons.item + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + + print (recipient) + if recipient = Void and last_error.is_empty and not back then + list_accounts + print ("Enter recipient account id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.accounts.valid_index (io.last_string.to_integer) then + store.accounts.go_i_th(io.last_string.to_integer) + recipient := store.accounts.item + else + last_error := "Error: Invalid account id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + + if last_error.is_empty and not back then + list_persons + print ("Enter person (authorized signer) id (b ...back): ") + io.readline + io.last_string.to_lower + if io.last_string.is_integer then + if store.persons.valid_index (io.last_string.to_integer) then + store.persons.go_i_th(io.last_string.to_integer) + account.transfer (amount, signer, recipient, store.persons.item) + Result := True + back := True + else + last_error := "Error: Invalid person id" + end + elseif io.last_string.is_equal ("b") then + back := True + else + last_error := "Error: Not a number" + end + end + end end delete_account @@ -785,12 +1112,12 @@ feature -- Basic operations last_error := "Account (#" + io.last_string + ") removed successfully" back := True else - last_error := "Invalid account id" + last_error := "Error: Invalid account id" end elseif io.last_string.is_equal ("b") then back := True else - last_error := "Not a number" + last_error := "Error: Not a number" end end end diff --git a/bank-eiffel/retireeaccount.e b/bank-eiffel/retireeaccount.e index 3db0cd4..24ae004 100644 --- a/bank-eiffel/retireeaccount.e +++ b/bank-eiffel/retireeaccount.e @@ -4,12 +4,23 @@ class inherit ACCOUNT redefine + add_authorized_signer, set_default_transfer_minamount end - + create make +feature -- Basic operations + + add_authorized_signer (an_authorized_signer: PERSON) + do + check + authorized_signers_only_one: get_authorized_signers.count = 0 + end + Precursor (an_authorized_signer) + end + feature {NONE} -- Implementation set_default_transfer_minamount diff --git a/bank-eiffel/studentaccount.e b/bank-eiffel/studentaccount.e index 04a9e31..abbb070 100644 --- a/bank-eiffel/studentaccount.e +++ b/bank-eiffel/studentaccount.e @@ -4,12 +4,23 @@ class inherit ACCOUNT redefine - set_default_transfer_minamount + set_default_transfer_minamount, + add_authorized_signer end create make +feature -- Basic operations + + add_authorized_signer (an_authorized_signer: PERSON) + do + check + authorized_signers_only_one: get_authorized_signers.count = 0 + end + Precursor (an_authorized_signer) + end + feature {NONE} -- Implementation set_default_transfer_minamount -- cgit v1.2.3