MainApplication.java 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. /**
  2. * Created by leon on 11/6/17.
  3. */
  4. public class MainApplication {
  5. public void runCreatePetList()
  6. {
  7. Console console = new Console();
  8. int numberOfPets = console.userSetNumberOfPets();
  9. Pet[] pets = new Pet[numberOfPets];
  10. Pet aPet = new Pet();
  11. for(int i=0; i<=numberOfPets-1; i++)
  12. {
  13. aPet.setTypeOfPet();
  14. aPet.setNameOfPet();
  15. if(aPet.getTypeOfPet().equalsIgnoreCase("dog"))
  16. {
  17. Dog aDog = new Dog(aPet.getTypeOfPet(), aPet.getNameOfPet());
  18. pets[i] = aDog;
  19. } else if(aPet.getTypeOfPet().equalsIgnoreCase("cat")){
  20. Cat aCat = new Cat(aPet.getTypeOfPet(), aPet.getNameOfPet());
  21. pets[i] = aCat;
  22. } else if(aPet.getTypeOfPet().equalsIgnoreCase("tortoise")){
  23. Tortoise aTortoise = new Tortoise(aPet.getTypeOfPet(), aPet.getNameOfPet());
  24. pets[i] = aTortoise;
  25. } else {
  26. pets[i] = aPet;
  27. }
  28. }
  29. console.printPets(pets);
  30. }
  31. }