Task 3.2.3 Practice Exercises – Implementing program logic
- Redefine the transfer method() of the Account class so that it re-uses the deposit() and withdraw() methods to subtract funds from the source account and add funds to the recipient account.
- Suppose we are required to provide an operation that allows us to add interest (given the current interest rate) to all account holders.
- What will the signature of the method look like?
- Give a possible implementation for that method.
- Implement a method to print the details of an Account object to the screen in the following format:
Name: Bob the Builder Balance: $1243.87
(all other details should be displayed)
How would you use this method to display the details for an account object from the main program?
- Discuss the design for a class to model a simple Person object in your Programming Squad.
You will need to consider the following details in your discussion:
- What information is common to all types of people?
- How would you create a new person object in another part of the program?
- What information might we need to retrieve from a Person object?
- What information might we need to change in a Person object?
- Consider how might you might update the Person class you have designed so that there is a connection between a Person and the parents of that Person (which are also Person objects), allowing for the names of a Person’s parents to be displayed with the Person’s details.
Discuss how the connection between a given Person and the two Person objects which represent the parents of the Person in question could be set up in the main program.