/* Cat.java example code AC Chapin */ package cis119.pkg11.methods; // a cat -- example of a class public class Cat { // INSTANCE VARIABLES public String name; public boolean hungry; // METHODS // make a noise public void miaow() { /* here we use the name and hungry variables for whatever Cat we called the method for so if we called mrWhiskers.miaow() then we will use mrWhiskers.name and mrWhiskers.hungry */ System.out.print("Miaow! I'm " + name); // conditional . . . we haven't talked about this yet // only print this part if the hungry // boolean is currently true if (hungry) { System.out.print(" and I'm hungry."); } System.out.println(); // newline } // eat a Bunny public void eat(Bunny food) { System.out.println(name + " is eating " + food.name + ". YUM!"); hungry = false; food.name = "Ex-Bunny"; } // toString method creates String representing the Cat @Override public String toString() { String str = name + " the "; if (hungry) { str += "hungry "; } return str + "cat"; } }