Answer to Question #239774 in Java | JSP | JSF for zakia kafeel

Question #239774

Create a class "House", with an attribute "area", a constructor that sets its value and a method

"ShowData" to display "I am a house, my area is 200 m2" (instead of 200, it will show the real

surface). Include getters an setters for the area, too.

• The "House" will contain a door. Each door will have an attribute "color" (a string), and a method

"ShowData" wich will display "I am a door, my color is brown" (or whatever color it really is).

Include a getter and a setter. Also, create a "GetDoor" in the house.

• A "SmallApartment" is a subclass of House, with a preset area of 50 m2.

• Also create a class Person, with a name (string). Each person will have a house. The method

"ShowData" for a person will display his/her name, show the data of his/her house and the data

of the door of that house.



1
Expert's answer
2021-09-22T00:05:56-0400
public class House {
    private double area;
    private Door door;

    public House(double area, Door door) {
        this.area = area;
        this.door = door;
    }

    public void showData() {
        System.out.println("I am a house, my area is " + area + " m^2");
    }

    public double getArea() {
        return area;
    }

    public void setArea(double area) {
        this.area = area;
    }

    public Door getDoor() {
        return door;
    }

    public void setDoor(Door door) {
        this.door = door;
    }
}


public class Door {
    private String color;

    public Door(String color) {
        this.color = color;
    }

    public void showData() {
        System.out.println("I am a door, my color is " + color);
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }
}


public class SmallApartment extends House {
    public SmallApartment(Door door) {
        super(50, door);
    }
}


public class Person {
    private String name;
    private House house;

    public Person(String name, House house) {
        this.name = name;
        this.house = house;
    }

    public void showData(){
        System.out.println(name);
        house.showData();
        house.getDoor().showData();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS