Last modified: January 09, 2024
In this lab, you will create a House class and read user input with the Scanner class.
Create a new class named in the format PX_LastName_FirstName_House
At the top of your program, write a multi-line comment stating
Declare some instance variables to keep track of
Then, add 2 constructors:
A default constructor that initializes the attributes as follows:
A second constructor that accepts parameters for number of doors, windows, bedrooms, and asking price
Then, add the following getter methods:
Add the following setter method:
Finally, add the following methods:
/** Calculate and return the market value for this house
Market value is $300,000 plus $55,000 per bedroom
plus $3,000 per window */
public double calculateMarketValue() {
// Add your code here
}
// Adds more windows to the house
public void addWindows(int num) {
// Add your code here
}
// Adds more doors to the house
public void addDoors(int num) {
// Add your code here
}
/** Adds more bedrooms to the house
Each new bedroom adds one new door and one new window */
public void addBedrooms(int num) {
// Add your code here
}
/** returns true if the asking price is less than the
calculated market value and false otherwise */
public boolean isBelowMarketValue() {
// Add your code here
}
/** returns a String specifying this house's
- number of bedrooms
- market value
- asking price */
public String toString() {
// Add your code here
}
Write a driver to test your House class using Scanner. Name your driver using the format PX_LastName_FirstName_HouseDriver
.
Create a default house and print out the result of calling toString() on the house.
Here is some sample output (your wording can vary):
A 3 bedroom house with a market value of $489000.0 is for sale with asking price $435000.0
Doors: 10 Windows: 8 Bedrooms: 3 Asking Price: $435000.0
How many doors do you want? 5
How many windows do you want? 8
How many bedrooms do you want? 2
What is your asking price? 378000
A 2 bedroom house with a market value of $434000.0 is for sale with asking price $378000.0
The asking price is below market value.
What is your new asking price? 567000
After adding a bedroom:
A 3 bedroom house with a market value of $492000.0 is for sale with asking price $567000.0
The asking price is above market value.
PX_LastName_FirstName_House
and PX_LastName_FirstName_HouseDriver
where X is your period.
For example, if your name is Michael Wang and you are in 2nd period, the classes should be named P2_Wang_Michael_House
and P2_Wang_Michael_HouseDriver
.PX_LastName_FirstName_House.java
and PX_LastName_FirstName_HouseDriver.java
. You should submit those two files below.You must Sign In to submit to this assignment