Description

This notebook contains a class which describes houses.

// Definition of class
public class house { 
    private int bedrooms;
    private int bathrooms;
    private int sqft;
    private float age;
    private String location;

    // Constructor called with no parameters. Different from class definition because it's missing the "class" keyword.
    public house() {
        // Constructor uses a non static setter method to assign the variable values of the class.
        this.setHouse(0, 0, 0, 0, "-1");
    }

    // Constructor called when parameters are given in creation of the object.
    public house(int bedrooms, int bathrooms, int sqft, float age, String location) {
        this.setHouse(bedrooms, bathrooms, sqft, age, location);
    }

    // Non static setter method sets the values of the variables in the object.
    public void setHouse(int bedrooms, int bathrooms, int sqft, float age, String location) {
        this.bedrooms = bedrooms;
        this.bathrooms = bathrooms;
        this.sqft = sqft;
        this.age = age;
        this.location = location;
    }

    // Non static getter method returns the number of bedrooms in the house object.
    public int getter() {
        return this.bedrooms;
    }

    public static void main(String[] args) {
        // Creating two instances of the house class. 
        house house1 = new house();
        house house2 = new house(4, 4, 3000, 5, "Zimbabwe");
        System.out.println("House 1 bedrooms: " + house1.getter());
        System.out.println("House 2 bedrooms: " + house2.getter());
    }
}

house.main(null);
House 1 bedrooms: 0
House 2 bedrooms: 4