Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a class called House to hold details of the location (street number, st

ID: 3916800 • Letter: 1

Question

1. Write a class called House to hold details of the location (street number, street name, town) and the year of construction and the property tax. Write the appropriate contructor, selector and mutator methods. Also write a toString method to return the details of the house.

2. Write a subclass Home with additional instance fields for the name of the occupying family and the date they moved in. You should use the OurDate class we wrote in the class. Note the following: There should be two overloaded constructor methods: public Home (int house, String street, String town, String family, OurDate movedIn) and public Home (int house, String street, String town, int yearConstructed, int propertyTax, String family, OurDate movedIn) These should make use of the super keyword where appropriate. There should be the usual methods to set and extract the values of the new instance fields: setFamily getFamily setDateMovedIn getDateMovedIn There should be a toString method that calls the toString method provided by the House class to return the details of the house and then return the text "has been occupied by FAMILY since DATE", with suitable values inserted. You should make the three classes (House, Home, OurDate) part of the package insy.java.hw6.

3. Write a simple driver application that prompts the user to enter the appropriate information about a home, creates an instance of the Home class, and then prints out the details of that home. Make sure to use the appropriate import statement(s) to import the above classes. Deliverables: You should submit the four source code files (House.java, Home.java, OurDate.java, HomeDriver.java).

Explanation / Answer

import java.util.*;

class OurDate
{
private int day,month,year;

public OurDate(int day,int month,int year)//constructor
{
  this.day = day;
  this.month = month;
  this.year = year;
}
public String toString()
{
  return ""+day+"/"+month+"/"+year;
}
}
class House   // base class
{
private int houseNumber;
private String streetName,town;
private int yearConstructed;
private int propertyTax;

// constructors
public House(int houseNumber,String streetName,String town)
{
  this.houseNumber = houseNumber;
  this.streetName = streetName;
  this.town = town;
  
}
public House(int houseNumber,String streetName,String town,int yearConstructed,int propertyTax)
{
  this.houseNumber = houseNumber;
  this.streetName = streetName;
  this.town = town;
  this.yearConstructed = yearConstructed;
  this.propertyTax = propertyTax;
}

public String toString()
{
  return " House# "+houseNumber +", "+streetName+" , "+town+" constructed in year : "+yearConstructed +" property Tax : "+propertyTax+"%";
}
}

class Home extends House // derived class
{
private String family;
private OurDate movedIn;


//constructors
public Home (int house, String street, String town, String family, OurDate movedIn)
{
  super(house,street,town);// call to base class constructor
  this.family = family;
  this.movedIn = movedIn;
  
}
public Home (int house, String street, String town, int yearConstructed, int propertyTax, String family, OurDate movedIn)
{
  super(house,street,town,yearConstructed,propertyTax);
  this.family = family;
  this.movedIn = movedIn;
}

//set and get methods
public void setFamily(String family)
{
  this.family = family;
}

public String getFamily()
{
  return family;
}
public void setDateMovedIn(OurDate movedIn)
{
  this.movedIn = movedIn;
}
public OurDate getDateMovedIn()
{
  return movedIn;
}

public String toString()
{
  return super.toString() +" has been occupied by "+family+" since "+movedIn;
}


}
class HomeDriver
{
public static void main (String[] args)
{
  Scanner scnr = new Scanner(System.in);
  
  System.out.println("Enter the house number : ");
  int houseNum = scnr.nextInt();
  
  System.out.println("Enter the street name : ");
  String street = scnr.next();
  
  System.out.println("Enter the town : ");
  String town = scnr.next();
  
  System.out.println("Enter year of construction : ");
  int year = scnr.nextInt();
  
  System.out.println("Enter property tax : ");
  int propertyTax = scnr.nextInt();
  
  System.out.println("Enter the name of the family : ");
  String family = scnr.next();
  
  System.out.println("Enter the date they moved in : ");
  int day = scnr.nextInt();
  int month = scnr.nextInt();
  int year1 = scnr.nextInt();
  
  OurDate d = new OurDate(day,month,year1);
  
  Home home = new Home(houseNum,street,town,year,propertyTax,family,d);
  
  System.out.println(home);
  
  
}
}

Output:

Enter the house number :345
Enter the street name :downstreet
Enter the town :NJ
Enter year of construction :2007
Enter property tax :6
Enter the name of the family :Johnsons
Enter the date they moved in : 21 11 2008

House# 345, downstreet , NJ constructed in year : 2007 property Tax : 6% has been occupied by Johnsons since 21/11/2008

Do ask if any doubt. Please upvote.