/** * A very simple shelter class should one of the uses of object inheritance * @author gtowell * Created: Feb 2021 */ public class GBShelter { // the store for the animals in the shelter private StuffBag animals; /** * initialize the shelter. */ public GBShelter() { animals = new StuffBag(100); } /** * Add an animal to the shelter * @param animal the animal to be added */ public void addAnimal(Pet animal) { animals.add(animal); } /** * Adopt a random shelter animal * @return an animal in the shelter */ public Pet adoptRoulette() { return animals.remove(); } @Override public String toString() { return animals.toString(); } public static void main(String[] args) { GBShelter shelter = new GBShelter(); shelter.addAnimal(new Dog("dave", "toy")); shelter.addAnimal(new WorkingDog("Jane", "BorderCollie")); shelter.addAnimal(new Cat("Calypso", "1", "Siberian")); Pet aa = shelter.adoptRoulette(); if (aa instanceof Cat) { Cat c = (Cat) aa; System.out.println("I Got a Cat!!!!" + c + aa); } System.out.println(aa); System.out.println(shelter); } }