/* Author: James Tam Version: Feb. 1, 2021 JT: Program has been over documented (for beginners) because it covers some complex concepts. */ public class Driver { public static void main(String [] args) { //JT: This is only an example, I am not a hoarder of cats //(or other pets for that matter). final int CAT_CAPACITY = 100; //Array index int currentCat; //References to cat objects. //Step 1 in creating an object (declaring a reference) Cat tigger; Cat temp; //Reference to an array. //Step 1 in creating an array of references (declaring a reference //to the array). Cat [] myBuddies; //Invalid at this point. //System.out.println(tigger.whatMood()); //New cat object //Step 2 in creating an object (calling the constructor) tigger = new Cat(); System.out.println("Single cat's mood: " + tigger.whatMood()); //New array, each element is empty/null. //Step 2 in creating an array of references (creating the array with //a specified size). myBuddies = new Cat[CAT_CAPACITY]; //As long as there's a cat show it's mood. System.out.println("Moods of my buddies..."); currentCat = 0; temp = myBuddies[currentCat]; while ((currentCat < myBuddies.length) && (temp != null)) { System.out.println("\t" + temp.whatMood()); currentCat++; temp = myBuddies[currentCat]; } //Step 3 in creating an array of references (creating the elements by //calling the constructor). myBuddies[0] = new Cat(Cat.SLEEPY); myBuddies[1] = new Cat(Cat.PLAYFUL); //As long as there's a cat show it's mood. System.out.println("Moods of my buddies...now that I have some friends"); currentCat = 0; temp = myBuddies[currentCat]; while ((currentCat < myBuddies.length) && (temp != null)) { System.out.println("\t" + temp.whatMood()); currentCat++; temp = myBuddies[currentCat]; } } }