123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import java.util.*;
  2. /**
  3. * Created by leon on 11/6/17.
  4. */
  5. public class MainApplication {
  6. public static void main(String[] args){
  7. int x = 0;
  8. Scanner in = new Scanner(System.in);
  9. System.out.println("How many pets do you have¿");
  10. int length = in.nextInt();
  11. List<Pet> talkingPets = new ArrayList<Pet>(length);
  12. for(int i = 0;i < talkingPets.size(); i++){
  13. System.out.println("What type of pet do you have¿");
  14. String petType = in.nextLine();
  15. System.out.println("What is your pet's name¿");
  16. String petName = in.nextLine();
  17. if(petType.equalsIgnoreCase("BabyDuck") || petType.equalsIgnoreCase("Baby Duck")){
  18. Pet babyDuck = new BabyDucks();
  19. babyDuck.setName(petName);
  20. talkingPets.add(babyDuck);
  21. } else
  22. if(petType.equalsIgnoreCase("kitty")){
  23. Pet kitty = new Cat();
  24. kitty.setName(petName);
  25. talkingPets.add(kitty);
  26. } else {
  27. Pet dog = new Dog();
  28. dog.setName(petName);
  29. talkingPets.add(dog);
  30. }
  31. for(Pet pett: talkingPets){
  32. System.out.println(pett.getName() + "says " + pett.speak() + "¿¿¿");
  33. }
  34. }
  35. }
  36. }