In: Computer Science
Please use very basic level of bluej thanks (please dont use advance techniques )
Write a class House that represents a house. It should contain instance data: house number, street, town, year when the house was built. Define House’s constructor to accept and initialize all instance data. Include getter (accessor) and setter (mutator) methods for all instance data. Provide a toString method that returns one line description of the house as String. Provide method isHistoric() that returns a boolean indicating if the house was older than 50 from now or not.
Create a TestHouse class with main method in it. Within main method instantiate three House objects of your choice. At least one home should be historic. For each object invoke methods toString and isHistoric, and also invoke different pair of getter and setter methods. Provide appropriate print statements to explain the result of each invoked method to user.
CODE IN JAVA:
House.java file:
public class House {
private String houseNumber;
private String street;
private String town;
private int year;
House(String houseNumber,String street,String town,int year){
this.houseNumber = houseNumber;
this.street = street;
this.town = town;
this.year = year;
}
public String getHouseNumber() {
return this.houseNumber;
}
public String getStreet() {
return this.street;
}
public String getTown() {
return this.town;
}
public int getYear() {
return this.year;
}
public void setHouseNumber(String number) {
this.houseNumber = number;
}
public void setStreet(String street) {
this.street=street;
}
public void setTown(String town) {
this.town=town;
}
public void setYear(int year) {
this.year=year;
}
public String toString() {
return this.houseNumber+", "+this.street+", "+this.town+", "+this.year;
}
public boolean isHistoric() {
if(2019-year>50)
return true;
return false;
}
}
TestHouse.java file:
public class TestHouse {
public static void main(String[] args) {
House h1 =new House("1-16","raja street","tekkali",2000);
House h2 =new House("1-17","pedda street","palasa",1990);
House h3 =new House("1-18","golla street","uppal",1947);
System.out.println("The house1 is:"+h1);
if(h1.isHistoric())
System.out.println("house1 is historic");
System.out.println("The house2 is:"+h2);
if(h2.isHistoric())
System.out.println("house2 is historic");
System.out.println("The house3 is:"+h3);
if(h3.isHistoric())
System.out.println("house3 is historic");
}
}
OUTPUT: