Closed

Java Programs

This project received 43 bids from talented freelancers with an average bid price of $274 USD.

Get free quotes for a project like this
Employer working
Skills Required
Project Budget
N/A
Total Bids
43
Project Description

11:45 PM PST 6/5/2012

Objective: To learn how to use an inner class, object-type class attributes, StringBuffer, null values, and self-referential classes.
Steps:
(i) Create a new folder called 'assign72' under C:\Java\Lesson7. Copy all files (except [url removed, login to view]) of assign 7.1 into this folder.
(ii) Modify classes as follows:

Class Name: Home

Attributes:
• Remove the attributes: 'value' and 'commission'
• Add a new attribute called 'hd' of type: HomeDerivedData
• Add a new attribute called 'nextHome' of type: Home

Constructor:
• constructor (homeType, age, sqft):
Modify this constructor to instantiate an object of the inner class HomeUtil and call computeDerivedData() on it, to update the 'hd' class attribute.
Set 'nextHome' attribute to 'null' (without the quotes). Note that null is valid to use as a value of any object, and means the object is 'undefined'.

Methods:
• Getters for all attributes
• Setter for 'nextHome' attribute only

Inner Class: Class Name: HomeUtil

Methods:
• Copy computeDerivedData() method from [url removed, login to view] of assign 7.1 into this inner class, and modify it so that it doesn't take any input parameters and has a return type of 'void'. Inside the method body, update the 'hd' attribute of the Home class, to set its 'value' and 'commission', using same formulae as in assign 7.1.

Class Name: HomeType

Attributes:
No change

Constructor:
No need to implement any constructor (as before)

Methods:
• Modify getTypeDescr() to return a StringBuffer instead of a String

Class Name: HomeDerivedData

Attributes:
No change

Constructor:
Add a default constructor

Methods:
No change

NOTE: [url removed, login to view]: NOT to be used anymore


(iii) Modify the TestHome test driver so that it instantiates three Home type objects, as follows:

• Home object # 1: Type: Single Family, age = 15 yrs, and sqft = 2000.
• Home object # 2: Type: Condo, age = 8 yrs, and sqft = 1500.
• Home object # 3: Type: Twon Home, age = 10 yrs, and sqft = 2500.

The 'nextHome' for Home object # 1 should be Home object # 2; similarly, the 'nextHome' for Home object # 2 should be Home object # 3. To achieve this, call setNextHome() on Home object # 1, sending it Home object # 2. Similary, call setNextHome() on Home object # 2, sending it Home object # 3.

Write a static method called 'printReport()' that takes a Home object, and a 'homeNbr' parameter of type: int. This method should print the content of the Home object (same as in assign 7.1, except that now the title for each home should include the home nbr. For example, for Home object # 1, it should say "Summary Report for Home # 1", and so on. Begin by copying the [url removed, login to view] lines from [url removed, login to view] of assign 7.1 into this method. Replace all [url removed, login to view] lines with String concatenation using the += operator, each time adding one line of output. Do NOT use one long String to concatenate all pieces, instead use += operator for each attribute of the Home object, and a SINGLE [url removed, login to view]() at the end of the method to dump the resulting String containing the full report for the Home object.

Inside main(), declare a temporary Home type object called 'hTmp', and assign it the first Home object. Declare a loop index called 'i' and initialize to 1. Then use a while loop that loops as long as hTmp is not null. In each iteration of the loop, call 'printReport()' passing it the 'hTmp' object and a home nbr (the loop index), then set 'hTmp' to be the next Home object each time. Increment 'i' at the end of the loop.


(iv) Compile [url removed, login to view], [url removed, login to view], [url removed, login to view], and then [url removed, login to view] and run the code. Verify that the output session looks similar to this:

C:\Java\Lesson7\assign72>javac [url removed, login to view]

C:\Java\Lesson7\assign72>javac [url removed, login to view]

C:\Java\Lesson7\assign72>javac [url removed, login to view]

C:\Java\Lesson7\assign72>javac [url removed, login to view]

C:\Java\Lesson7\assign72>java TestHome
Summary Report for Home # 1
Type: Single Family
Age: 15

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online