12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import java.util.Scanner;
  2. /**
  3. * Created by leon on 11/6/17.
  4. */
  5. public class MainApplication {
  6. public static void main(String[] args) {
  7. Scanner s = new Scanner(System.in);
  8. System.out.println("Hello! How many pets do you have?");
  9. int numPets = s.nextInt();
  10. s.nextLine();
  11. System.out.println("Thank you for telling me.");
  12. Pet[] yourPets = new Pet[numPets];
  13. for (int i = 0; i < numPets; i++) {
  14. System.out.print("Enter the name of your pet: ");
  15. String name = s.nextLine();
  16. System.out.print("What kind of pet is " + name + "? ");
  17. String type = s.nextLine();
  18. if (type.equalsIgnoreCase("cat")) {
  19. yourPets[i] = new Cat(name);
  20. }
  21. else if (type.equalsIgnoreCase("dog")) {
  22. yourPets[i] = new Dog(name);
  23. }
  24. else if (type.equalsIgnoreCase("capybara")) {
  25. yourPets[i] = new Capybara(name);
  26. }
  27. else {
  28. yourPets[i] = new Pet(name);
  29. }
  30. }
  31. System.out.println("Your pets are the following: ");
  32. for (int i = 0; i < numPets; i++) {
  33. System.out.println("Your " + yourPets[i].getName() + " says " + yourPets[i].speak());
  34. }
  35. }
  36. }