/* BunnyHarness.java example code AC Chapin */ package cis214c04classmethods; /** * example of using objects with constructors, accessors, mutators */ class BunnyTestHarness { // main method tests out Bunny class public static void main(String[] args) { // created Bunny using default constructor Bunny bugs = new Bunny(); // values from default constructor System.out.println("first : [" + bugs.getName() + "] has [" + bugs.getCarrotCount() + "] carrots."); // use accessors and mutators bugs.setName("Bugs Bunny"); bugs.setCarrotCount(5); System.out.println("later : [" + bugs.getName() + "] has [" + bugs.getCarrotCount() + "] carrots."); // class methods bugs.sayHi(); bugs.feed(2); bugs.hop(); // automatic call to tostring System.out.println("so that was " + bugs); // Bunny created using parameterized constructor Bunny babs = new Bunny("Babs Bunny", 6); // values from parameterized constructor System.out.println("first : [" + babs.getName() + "] has [" + babs.getCarrotCount() + "] carrots."); // accessors and mutators babs.setName("Barbara J. Bunstein"); babs.setCarrotCount(16); System.out.println("later : [" + babs.getName() + "] has [" + babs.getCarrotCount() + "] carrots."); // class methods babs.sayHi(); babs.feed(9); babs.hop(); // automatic call to tostring System.out.println(babs + " is finished"); } }