I need a generic base class called building that stores the number of floors a building has, the number of rooms, and its total square footage. I also need a derived class called house that inherits building and stores the number of bedrooms and bathrooms, and another derived class named office that too inherits building and stores the number of fire extinguishers and telephones.
I have to create a Java Application program that demonstrates this class hierarchy and provide all necessary methods. The classes have to be tested using the following main method.
public class TestBuildings
{
public static void main(String[] args)
{
building building1 = new building(1, 10, 6000);
building building2 = new building();
System.out.println();
house house1 = new house(1, 5, 3000);
house house2 = new house(2, 2);
System.out.println();
office office1 = new office(1, 2, 15000);
office office2 = new office(2, 6, 15000, 6, 30);
System.out.println();
//change building properties
building2.setFloors(3);
building2.setRooms(12);
building2.setFeet(20000);
System.out.println("Building 2: \n" + building2.toString() + "\n\n");
//change house properties
house1.setBedrooms(3);
house1.setBaths(3);
house2.setFloors(2);
house2.setRooms(10);
house2.setFeet(4200);
System.out.println("House 1: \n" + house1.toString() + "\n\n");
System.out.println("House 2: \n" + house2.toString() + "\n\n");
//change office properties
office1.setFireExt(4);
office1.setTelephones(50);
System.out.println("Office 1: \n" + office1.toString() + "\n\n");
}
}
This is what I have for class building
public class building
{
private int floors;
private int rooms;
private int sqft;
public void setFloors(int floors)
{
this.floors = floors;
}
public int getFloors()
{
return floors;
}
public void setRooms(int rooms)
{
this.rooms = rooms;
}
public int getRooms()
{
return rooms;
}
public void setFeet(int sqft)
{
this.sqft = sqft;
}
public int getFeet()
{
return sqft;
}
}
This is my class house
public class house extends building
{
private int bedrooms;
private int baths;
public void setBedrooms(int bedrooms)
{
this.bedrooms = bedrooms;
}
public int getBedrooms()
{
return bedrooms;
}
public void setBaths(int baths)
{
this.baths = baths;
}
public int getBaths()
{
return baths;
}
}
And finally, class office
public class office extends building
{
private int fire;
private int phones;
public void setFireExt(int fire)
{
this.fire = fire;
}
public int getFireExt()
{
return fire;
}
public void setTelephones(int phones)
{
this.phones = phones;
}
public int getTelephones()
{
return phones;
}
}
My question, what to I have to add, subtract, or modify in my three classes to make the main method work? Do I need arrays in there somehow?
Any help will be greatly appreciated. Thanks!
house extends building-->House extends Building