Tags: %TAGME{ tpaction="" web="Main" tag="" }% view all tags

Account and Customer Class

Moodle Link

This will be started in class. Each student is to complete and test their own after class, and turn it in as a homework on the moodle link above.

Group 1

https://repl.it/join/rqeimybu-jimskon

Group 2

https://repl.it/join/mgkdzcag-jimskon

Group 3

https://repl.it/join/xhiivcuk-jimskon

Group 4

https://repl.it/join/mnzxvwwq-jimskon

Group 5

https://repl.it/join/dxfanbje-jimskon

Template

https://repl.it/@JimSkon/ClassBank

Consider the class to represent bank accounts from last week:

https://repl.it/@JimSkon/ClassBankBegin

Consider an alternative design. We actually have two classes, accounts and customers.

An account has the following:

  • An account name
  • An associated customer (not just a name)
  • A balance
  • An interest rate (0-100) And we can do the following with an account (methods):
  • __init__(self, name, cust, balance=0, interest=0)
  • withdraw(self, amount)
  • deposit(self, amount)
  • getBalance(self)
  • getName(self)
  • getCust(self) where cust is a Customer object (below), not a customer name

    And we also have a customer with the following:
  • Name
  • Address
  • Phone
  • Social Security Number

    And the following methods:
  • __init__(self, name, address, phone, SSN)
  • getName(self)
  • getAddress(self)
  • getPhone(self)
  • getSSN(self)
  • setName(self, name)
  • setAddress(self, address)
  • setPhone(self, phone)
  • setSSN(self, ssn)

Step 1 - Try it out

Consider a start on this application: https://repl.it/@JimSkon/ClassBankBegin

Note that this has two classes, an account and a customer class. The customer class is incomplete (it only has the name).

The code maintains a list of customers (in the customers list) and a list of accounts (in the accounts list), It has a menu:

  1. Add a customer

  2. List customers
  3. Add an account
  4. List all accounts
  5. List account by customer
  6. Pick an account and deposit
  7. Pick an account and withdraw
  8. Add monthly interest to all accounts
  9. Exit In this program you can add customers and accounts.

Note that you MUST add customers first, as the accounts refer to the associated customer. The self.customer field in the account is actualy a reference to the customer.

So when you add an account, the customers are listed, and you pick from the list so the new account can actually refer to the customer. When we say a account refers to a customer, it means there is a single copy of each customer.

Try it out! Add several customers, then list hem. Then add a few accounts. Try adding more than one accout with the same customer.

Step 2 - Finish the customer class

Note that the customer account only has a single field. Add the address, phone, and SSN.

You will need to

  1. Modify the Customer class to include the new fields. This includes adding the fields to the __init__ method..

  2. You will need to add need new methods to the customer class to deal with the fields, getAddress, setAddress, getPhone, setPhone, getSSN, setSSN.

  3. You will need to modify the displayCustomer function in main.py to display the new fields.

  4. You wil need to modify the addCust function to ask for the new fields, and send them to the constructor.

Step 3 - Add an interest rate to Account

Here you are to update the Account class to include an interest rate. This is a float where 3.5 represents and interest rate of 3.5% for a year.

You will need to:

  1. Modify the Account class to include the interest field. This includes adding the field to the __init__ method..

  2. You will need to add need new methods to the customer class to deal with the fields, getInterest, setInterest.

  3. You will need to modify the displayAccount function in main.py to display the new field.

  4. You wil need to modify the addAcc function to ask for the new field, and send them to the constructor.

Step 4 - Add the change customer name option

You should make the changes to allow the "Change customer name" option to work.

You should then do a run to make sure it works:

  1. Add several customers
  2. Add two accounts with the same customer (a savings and a checking account)
  3. Change the that customers name
  4. Do a list of all accounts.
  5. Verify that the customers names changes on both accounts
  6. Explain why this works

Step 5 - List accounts by customer

Add the functionality for "List account by customer" option. This option should list all the customers, and allow the user to pick one. It will then list all the information on the accoutns just for this customer.

How will you do this?

Step 6 - Pick an account and depost option

Add the functionality for the "Pick an account and depost money" option.

Try it out.

Step 7 - Pick an account and withdraw option

Add the functionality for the "Pick an account and withdraw money" option.

Try it out.

Step 8 - Add monthly interest

You are to add the functionality to add the interest for one month to all the accounts. HOw will you do this.

Test this out.

Edit | Attach | Watch | Print version | History: r5 < r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r5 - 2020-04-14 - JimSkon
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback