Constructors giving me an headache Java

public class Coffee {

    //Instance Variables        
    private double sugar;
    private int milk;
    private boolean isHot; // renamed heat to isHot
    private int size;

    // Constructor       
    public Coffee (double id, int dairy, boolean temp ) {
        sugar = id;
        milk = dairy;
        heat = temp;        
    }

    // (setter)
    public void setSugar(double id) {
        this.sugar = id;
    }
    public void setMilk(int dairy) {
        this.milk = dairy;
    }       
    public void setSize(int size) {
        this.size = size;
    }

    public void setHeat(boolean isHot) {
        this.isHot = isHot;
    }

    //(getter)  
    public double getSugar() {
        return this.sugar;
    }

    public int getMilk() {
        return this.milk;
    }

    public boolean checkIfHot() {
        return this.isHot;
    }

    public int getSize() {
        return this.size;
    }

    // Method to display data, (need to work on this)
    static void display() {
        System.out.println("You added " + getSugar() + " tablespoons of sugar to your coffee");
        System.out.println("You have " + getMilk() + " in your coffee");
        System.out.println("That's a " + getSize() + " ounce cup");
        System.out.println("Is the cup hot? " + checkIfHot());
    }

    // Default Constructor (need help with setting heat to a default)       
    public Coffee() {
        sugar = 0.0;
        milk = 0;
        heat = false;
        size = 0;
    }  
}

Here you go. I have renamed your boolean private member heat to isHot.

Browse More Popular Posts

Leave a Comment