Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
2.0 kB
14
Indexable
Never
public class House {
    int numOfBedrooms;
    double famRoomArea;
    double livingRoomArea;
    String houseStyle;
    double acres;

    House(){
        numOfBedrooms = 0;
        famRoomArea = 0;
        livingRoomArea = 0;
        houseStyle = "";
        acres = 0;
    }

    House(String houseStyle,double areaOfFamRoom, double areaOfLivingRoom, int numOfBedrooms, double acres){
        this.houseStyle = houseStyle;
        this.famRoomArea = areaOfFamRoom;
        this.livingRoomArea = areaOfLivingRoom;
        this.numOfBedrooms = numOfBedrooms;
        this.acres = acres;
    }

    int getBedrooms(){return numOfBedrooms;}
    double getFamilyRoomArea(){return famRoomArea;}
    double getLivingRoomArea(){return livingRoomArea;}
    double getPlot(){return acres;}
    String getStyle(){return houseStyle;}

    double getTotalArea(){
        return getFamilyRoomArea() + getLivingRoomArea() + 300*(getBedrooms());
    }

    int compareArea(House otherHouse) {
        if (otherHouse.getTotalArea() == getTotalArea()){
            return 0;
        }
        if (otherHouse.getTotalArea() > getTotalArea()) {
            return 1;
        }
        else{
            return -1;
        }

    }
    void setBedrooms(int numOfBedrooms){
        this.numOfBedrooms = numOfBedrooms;
    }
    void setFamilRoomArea(double famRoomArea){
        this.famRoomArea = famRoomArea;
    }
    void setLivingRoomArea(double livingRoomArea){
        this.livingRoomArea = livingRoomArea;
    }
    void setPlot(double acres){
        this.acres = acres;
    }
    void setStyle(String houseStyle){
        this.houseStyle = houseStyle;
    }


    String showHouse(){
        return "House style = "+ getStyle() + "\nBedrooms = " + getBedrooms() + "\nFamily room area = " + getFamilyRoomArea() + "\nLiving room area = " + getLivingRoomArea() + "\nSquare feet = " + getPlot();
    }



}
Leave a Comment