12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import java.util.*;
  2. public class MainApplication {
  3. enum petTypes {CAT, DOG, FISH};
  4. public static void main(String[] args){
  5. Scanner scan = new Scanner(System.in);
  6. System.out.println("How many pets do you have?");
  7. int numberOfPets = scan.nextInt();
  8. scan.nextLine();
  9. Pet[] petArr = new Pet[numberOfPets];
  10. for(int i = 0; i < numberOfPets; i++){
  11. System.out.println("What type of pet?");
  12. String typeOfPet = scan.nextLine();
  13. System.out.println("Name?");
  14. String namePet = scan.nextLine();
  15. switch(petTypes.valueOf(typeOfPet.toUpperCase())){
  16. case CAT:
  17. petArr[i] = new Cat(namePet);
  18. break;
  19. case DOG:
  20. petArr[i] = new Dog(namePet);
  21. break;
  22. case FISH:
  23. petArr[i] = new Fish(namePet);
  24. break;
  25. }
  26. }
  27. for(Pet i : petArr){
  28. System.out.println
  29. (i.getType() + " : " + i.getName() + " says: " + i.setSpeak());
  30. }
  31. }
  32. }