SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Classes And Object Oriented Programming
Exercise:
Algorithm Workbench
Question:3 | ISBN:9780132576376 | Edition: 2

Question

3. Look at the following description of a problem domain:
The bank offers the following types of accounts to its customers: savings accounts,checking accounts, and money market accounts. Customers are allowed to deposit money into an account (thereby increasing its balance), withdraw money from an account
(thereby decreasing its balance), and earn interest on the account. Each account has an interest rate.
Assume that you are writing a program that will calculate the amount of interest earned for a bank account.
a. Identify the potential classes in this problem domain.
b. Refine the list to include only the necessary class or classes for this problem.
c. Identify the responsibilities of the class or classes.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

a. Potential classes in this problem domain could include:

  • Bank (representing the bank itself)
  • Customer (representing a bank customer)
  • Account (representing a bank account)
  • SavingsAccount (a specific type of account)
  • CheckingAccount (a specific type of account)
  • MoneyMarketAccount (a specific type of account)

b. Refined list of necessary classes for this problem:

  • Customer
  • Account (parent class for all types of accounts)
    • SavingsAccount (inherits from Account)
    • CheckingAccount (inherits from Account)
    • MoneyMarketAccount (inherits from Account)

c. Responsibilities of the classes:

  • Customer:
    • Maintain customer information (name, address, etc.)
    • Interact with accounts (deposit, withdraw, earn interest)
  • Account:
    • Hold common attributes and methods shared by all types of accounts:
      • Account number
      • Balance
      • Interest rate
      • Deposit money
      • Withdraw money
      • Calculate interest earned
  • SavingsAccount (subclass of Account):
    • Specific behavior related to savings accounts
  • CheckingAccount (subclass of Account):
    • Specific behavior related to checking accounts
  • MoneyMarketAccount (subclass of Account):
    • Specific behavior related to money market accounts

Each class will have its own set of attributes and methods specific to its responsibilities within the problem domain. The Account class will serve as the parent class for all types of accounts, providing a common interface and shared functionality, while the subclassed accounts will have additional behaviors unique to their specific types.

0 0

Discussions

Post the discussion to improve the above solution.