0
public class Cow{
    
    public static void main(String[] args) {
        Cow may = new Cow("Corny", "moo");
        milkCow();
        System.out.println(may.getNumMilkings());
    }
    
    private String type;
    private String sound;
    private int numMilkings;
    
    public Cow(String t, String s){
        type = t;
        sound = s;
        numMilkings = 0;
    }
    
    public String getSound(){
        return sound;
    }
    
    public String getType(){
        return type;
    }
    public void milkCow(){
        numMilkings++;
    }
    public int getNumMilkings(){
        return numMilkings;
    }
}

There is a problem with me calling milkCow() in the main method. I wanted to use milkCow() to increase the value of numMilkings by 1.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

0 Answers0