Question: Java programming. Only public and private classes allowed. a) Define a class named House that store information about a house. It should comprise the following:
Java programming. Only public and private classes allowed.
a) Define a class named House that store information about a house. It should comprise the following:
1. Private instance variables to store age of the House, its type (Detached, Semi-Attached, Attached) and its cost.
2. 4 constructors: No argument (sets age to 50, type to Attached and cost to 100000), one argument constructor (sets cost to a value, age - 50 and type - Attached), two argument constructors (sets age to a value, cost to a value , and type to Attached), three argument constructors (sets age to a value, cost to a value, and type to Attached, semi-detached, or detached)
3. 3 Accessor methods: - methods to return age, type and cost respectively
4. 5 Mutator methods: - 3 methods for setting the three values independently, a method to set all three values and a method to set age and cost of the house.
5. A public method called estimatePrice() that returns cost of a house based on type and age. An attached costs $100,000, appreciates 1% every year in first five years and 2% every year afterwards. A Semidetached costs $150,000, appreciates 2% every year in first five years and 3% every year afterwards. A detached costs $200,000, appreciates 2% every year in first five years and 2% every year afterwards.
6. A toString() method that returns type of the house and its age and its cost.
7. An equals() method to test for equality of two objects of class House based on type and age.
8. isLessThan() and isGreaterThan() method to compare between the prices of two objects of class House.
b) Write a test code
1. Which declares 4 house objects using 4 different constructors and output description of the 4 houses.
2. Test your accessor methods.
3. Calculate the estimated price of houses given type and age (include 1 attached and 1 detached).
4. Test out all 5 mutator methods to modify the attributes of different House objects.
5. Test methods toString(), equals() , isLessThan() and isGreaterThan() for different House objects.

Screen Shot 2018-11-12st 12.22.44 Question 2 (Simple Class Exercise) a) Define a class named House that store information about a house. It should comprise the 1. Private instance variables to store age of the House, its type (Detached, Semi- 2. 4 constructors: No argument (sets age to 50, type to Attached and cost to 100000), 1. Interpret both semi-detached and semi-attached as the same - use either of the terms. 2. The default age is mentioned 50, but it should be the year 1950 Attached, Attached) and its cost. one argument constructor (sets cost to a value, age 50 and type Attached), two argument constructors (sets age to a value, cost to a value, and type to Attached], three argument constructors (sets age to a value, cost to a value, and type to Attached, semi-detached, or detached) Corrections in the output: 3. 3 Accessor methods: methods to return age, type and cost respectively 4. The problem is the price of the house exceeded from the its initial value. The ccrrect output is 5 Mutator methods:-3 methods for setting the three values independently, a method to set all three values and a method to set age and cost of the house. House H1: This House is type attached. Its age is 1950 and costs $100000.0 House H2: This House is type attached. Its age is 1950 and costs $100000.0 House H3: This House is type attached. Its age is 4 and costs $100000.0 House H4: This House is type detached. Its age is 2 and costs $200000.0 5. A public method called estimatePricel that returns cost of a house based on type and age. An attached costs $100,000, appreciates 1% every year in first five years and 2% every year afterwards. A semidetached costs $150,000, appreciates 2% every year in first five years and 3% every year afterwards. A detached costs $200,000, appreciates 2% every year in first five ear s and 2 % every year afterwards. A toStringl) method that returns type of the house and its age and its cost. and age. objects of class House. Accessor Method: The housetype for house H4 is detached, its age is 2, and it costs $200000.0 6. 7. An equals() method to test for equality of two objects of class House based on type The estimated price of house H3 is $104000.0 The estimated price of house H4 is $208000.0 8. isLessThan() and isGreaterThan() method to compare between the prices of two b) Write a test code Mutator Method: The new age for house H3 is 5 Mutator Method: The new housetype for house H3 is semi-detached Mutator Method: The new cost for house H3 is 240000.0 Mutator Method: The new house H3 age is 6 and its new cost is 245000.0 Mutator Method: The new housetype for house H3 is semi-detached, its new age is 14and its cost is 260000.0 1. Which declares 4 house objects using 4 different constructors and output description of the 4 houses. Test your accessor methods. Calculate the estimated price of houses given type and age (include 1 attached and 1 detached). 2. 3. toString: This House is type semi-detached. Its age is 14 and costs $260000.0 COMP248/Fall 2018-Assignment 3 Page 3 of 5 Houses H1 and H2 are equal is true Houses H1 and H4 are equal is false House H4 is less than H3 is true House Hl is greater than H3 is false 4. Test out all 5 mutator methods to modify the attributes of different House objects. S. Test methods toString(), equals)isLessThanl) and isGreaterThan() for different House objects
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
