/** * Created by leon on 11/6/17. */ import java.util.Scanner; public class MainApplication { // int numOfPets; // String kindOfPets; public static void main(String[] args) { System.out.println("How many pets do you have?"); Scanner scan = new Scanner(System.in); int numOfPets = scan.nextInt(); Pet[] kind = new Pet[numOfPets]; int counter = 1; for (int i = 0; i < numOfPets; i++) { System.out.println("What kind is animal #" + counter + "?"); String animal = scan.next(); if (animal.equalsIgnoreCase("Dog")) { Pet dog = new Dog(); String name; System.out.println("What is their name?"); name = scan.next(); dog.setName(name); kind[i] = dog; //kind[i].speak(); } else if (animal.equalsIgnoreCase("Cat") ) { Pet cat = new Cat(); String name; System.out.println("What is their name?"); name = scan.next(); cat.setName(name); kind[i] = cat; } else if (animal.equalsIgnoreCase("Pig")) { Pet pig = new Pig(); String name; System.out.println("What is their name?"); name = scan.next(); pig.setName(name); kind[i] = pig; } else { System.out.println("Please enter a valid type"); } counter ++; //System.out.println(kind[i].getName()); } System.out.println(); for (int i = 0; i < numOfPets; i++){ System.out.println("" + kind[i].getName() + " says " + kind[i].speak()); } } }