JDEP 183H

Fall 2006

 

Homework Assignment 5:  “I want the program to do more things!”

 

Assigned:  November 16, 2006

Due:  December 7, 2006

 

Note: This assignment is to be completed individually - collaboration is strictly prohibited.

Points100 points

 

Objectives

 

The objectives of this homework assignment:

  1. Familiarize with the concept of Inheritance
    1. Understand the relation between Super and Sub Classes
    2. Define reusable classes based on inheritance
    3. Appreciate the usefulness of inheritance
  2. Familiarize with the concept of Polymorphism
    1. Text Box: “It would be nice for the program to do financial calculations for buying a car!”

“Why bonds only?  I deal with house mortgages.”

“How easy is it to extend this program?  What if we keep adding new ‘items’ like buying a car, buying a racehorse, buying a house, buying a private jet, buying a baseball team, etc.?”

“Okay, I can see the usefulness of this program.  But it is not general enough.”

“If I want to have a similar program that deals with buying a house, what should I do? Copy the program and then modify it so it stands alone?”


Appreciate the usefulness of polymorphism
  1. Familiarize with the use of protected modifier
  2. Understand basic GUI objects
  3. Write a GUI application
    1. Identify the GUI objects that are necessary for the application
    2. Organize the positions and functions of these GUI objects for the application
    3. Design the application such that the user interface is sensible and user-friendly
  1. Master good programming style and design
  2. Master code documentation, compilation, and execution
  3. Expose to Java syntax, programming styles, and Java classes

 

 Problem Description

 

I want the program to do more things! 

 

ABC tested and demonstrated your BondCalculater prototype to its customers.  The customers were excited and, of course, as a result, wanted the program to do more things. See the memos on the right.

 

Text Box: Memo To: Chief programmer
Memo From: Your boss

I am not good with programming but I have promised the customers that your way of programming definitely can speed up the process.  Something like “inheritance”? “polymorphism”?  Something like that?  

So, for this, not only do I want a second prototype, I also want some documentation on whatever you employ to help speed up the development process.  

Good luck!  

P.S.  You have to teach me about inheritance and polymorphism one of these days so I can explain it better to the customers.
ABC promised the customers that a second prototype would be ready in no time, since the program had been developed with further extensions in mind in the first place.  And the key to this second prototype is to show the customers that the program can do a variety of tasks with some common and similar characteristics, and that this extension can be done relatively easily.  See the memo below.

 

ABC has thus decided to add two new items to the program.  Previously, the prototype was a GUI that allows users to enter information for a Bond object and then perform some calculations.  Now, they want the second prototype to handle bonds, houses, and cars.  And instead of a BondCalculater, this second prototype will be called the FinancialCalculator.

 

And this time around, assume that all information will be entered one by one through the prototype GUI.  (If you want to keep the file-based entry of the first prototype, it will be okay to do so.)

 

Now, you already have been given the specifications on bond-related calculations (see HW#4). Here are some specifications for the other two types.

 

House-Related Financial Calculations

You bought a house several years ago when interest rates where very high.  As a consequence, your monthly payments are high as well.  You currently still owe OWED dollars.  You are thinking of refinancing and have two alternatives. 

1.      The first alternative is a  year mortgage.  You pay a fee () of a certain percent of the amount owed and refinance the entire amount owed at a fixed effective annual interest rate ().  The rate assumes monthly compounding.  Remember that the opportunity cost of your money is the market effective annual interest rate () which is compounded monthly.

2.      The second alternative is a new kind of mortgage.  You make the same payment every month for  years.  However, the payment is calculated by discounted at one rate () for the first  years and a second rate () for the remaining  years.   Each rate assumes monthly compounding.  This refinance plan involves an up-front fee () equal to a certain percent of the amount owed.  Remember that the opportunity cost of your money is the market effective annual interest rate () which is compounded monthly.

Which alternative has a lower present value?  What are the monthly payments under each alternative?

 

Car-Related Financial Calculations

You need a car.  There are three ways to get one.

1.      You pay cash for the car at an agreed upon price (PRICE) and then get a rebate (REBATE).

2.      You finance the car by agreeing to a price (PRICE), putting a certain amount down () and then financing the rest over T months at a below market effective annual interest rate () which is compounded monthly.  Remember that the opportunity cost of your money is the market effective annual interest rate () which is compounded monthly.

3.      You lease the car by putting a certain amount down (), making S monthly payments (LSPMNT) and then making a large final payment of FINAL.  Remember that the opportunity cost of your money is the market effective annual interest rate () which is compounded monthly.

Show the present value of the cost of each alternative.  Indicate which is least expensive.  Show the monthly payments associated with the financing and leasing alternatives.

 

In terms of the GUI prototype, here is a flow suggested by ABC.  You are encouraged to add to the flow.   Note that in the following, the Welcome, Choices, Information Entry, and Outcome Display modules should be windows or GUI panels.  Information processing is a module that should not need a GUI panel.  Basically, when the user runs the prototype, he or she first sees the Welcome panel.  And then he or she clicks a button to continue to the next panel, which has three choices.  The user chooses one (bond-related, house-related, or car-related) and a corresponding GUI panel will pop up.  This Information Entry panel will have unique sets of input fields to obtain information about a particular item.  After the user enters all the needed information for a particular item, he or she can click, say, a “process” button.  And the program crunches the numbers and outputs the outcome.  Note that the Outcome Display panel could be the same GUI panel that takes in the information, as long as it is well designed.  Note that the user should be allowed to change their information entry and re-process.  (Hint: Think carefully on how to design this well so that the GUI is user-friendly.)  After the user is satisfied with a particular item, he or she will be prompted to either continue with the system or quit.  If the user chooses to quit, the program should close all windows and terminate.  Otherwise, it should close all windows except the Choices panel.


 


Once again, there are two sets of problems to solve.  First and foremost, how should you design the objects?  How many objects are there?  There should be at least three: Bond, Car, and House.  You have already defined Bond in the first prototype.  Now, you are required to use inheritance and polymorphism.  That means that you are required to also create some parent class and child classes.  You have to decide which data members and methods should be inherited, which should be overridden, which should be unique.  ABC is counting on you to do this effectively so that they can convince the customers that with this development process, it is relatively easy to further extend the prototype to do even more things. (Hint:  Start with the three classes of objects, and then identify the commonalities!)

 

Second, how should you design the application?  The application should be called FinancialCalculator.java which instantiates and manipulates the objects.  For each particular item, what is the information that the program must solicit from the user?  Can inheritance be employed to make instantiation and presentation of objects more effective? What are the calculations that must be performed?  Can polymorphism be employed to make coding more efficient? What is the output?  (For the equations for the calculations, please see the Appendix.)

 

ABC also wants you to know that this specification of this second prototype is rather general and not very detailed.  It is intentional as they now trust you to be able to make the appropriate design decisions, especially in creating classes not specifically identified in the above specification.  There are many ways to design this prototype such that it will give the correct results.  However, a good solution is one that uses inheritance and polymorphism.  Remember that coming up with a good hierarchy of classes that utilize inheritance and polymorphism effectively and efficiently is very important for this assignment. 

 

Challenge - Extra Credit (10 points)

 

You are curious about your retirement.  You were born on January 1 and you are currently AGE years old.  Your current annual income is INCOME.  You get paid twice a month, on the 1st and the 15th.  You expect to get average annual raises of RAISE percent per year.  Raises are given July 1.  You plan to work to age RETIRE.  You already have CURRENT dollars in your retirement account.  Your retirement account is earning R percent APR per year.  The retirement account compounds quarterly.  You plan to put ADD percent of your income into your account each pay period until you retire.

 

Once you retire, you get a payment at the end of each month.  Statistics show that you can expect to live to age DEATH.  During your retirement, the expected annual inflation rate is INFLATE and you can expect to earn the same return on your account as you earned while you were working.  Again, assume quarterly compounding.  How much will you have in your retirement account when you retire?  How much can you draw from the account each month in real dollars to just use it up by the time you die?

 

Add the above “retirement” item to the FinancialCalculator, fully incorporating the Retirement class of objects into your hierarchy.  If you choose to solve this challenge, please include in your documentation (see Submission procedure below) on your use of inheritance and polymorphism.  Also include a discussion on what this extension entails (e.g., is inheritance useful in this case? Is polymorphism useful in this case?).

 

Submission Procedure

 

This assignment is due on December 7, 2006 at the start of class (12:30 PM).  Assignments five minutes late will NOT be accepted.  It is highly recommended that you read the grading policy and grading guidelines on the course website for a complete explanation of how the assignments will be graded. Remember, your program should follow a good programming style, include plenty of comments – both inline documentation and Javadoc documentation, and perform all of the functionality outlined above. Also, in the welcome message of your program, state whether you are implementing the extra credit functionality. 

 

There are two submission steps:

 

(1)    You must “handin” the following files on-line:

1.      Source files: Bond.java Car.java House.java FinancialCalculator.java *.java

2.   Compiled files: Bond.class Car.class House.class FinancialCalculator.class *.class

3.   Readme file:  README

4.   A report that consists at least:

(1) one diagram of classes and sub-classes of your implementation,

(2) an inventory (table) of the data members and methods of the Bond.java class that clearly indicates how each member or method has been re-organized (e.g., promoted to a parent class? Not modified at all?  Renamed?),

(3) tables that clearly show the inherited data members and methods, non-inherited and unique data members and methods, and inherited but overridden data members and methods, and

(4) clearly illustrated occurrences where polymorphism is used.

5.   Testing file:  TEST, and all screen snapshots if applicable

 

(2)    You must submit a stapled paper copy of a coversheet, your source files, the README file, and all the testing files. 

 

Both of these steps must be done by the start of the class on the day the assignment is due.  Please download this coversheet from the instructor’s course website, under the Homework Assignments link.   This coversheet allows the grader to give comments and categorize the points for your homework.

 

Appendix 

 

House

 

Alternative (1):  A  year mortgage. 

   and  

   and 

 

 

 

Alternative (2):  A new kind of mortgage. 

 

   and  

   and  

   and  

 

 

 

 

Car

 

Alternative (1):  Pay cash

 

 

Alternative (2):  Finance the car

 

   and  

   and 

 

 

 

Alternative (3):  Lease the car

 

   and