123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import java.util.*;
- /**
- * Created by leon on 11/6/17.
- */
- public class MainApplication {
- public static void main(String[] args){
- int x = 0;
- Scanner in = new Scanner(System.in);
-
- System.out.println("How many pets do you have¿");
- int length = in.nextInt();
- List<Pet> talkingPets = new ArrayList<Pet>(length);
-
- for(int i = 0;i < talkingPets.size(); i++){
-
- System.out.println("What type of pet do you have¿");
- String petType = in.nextLine();
-
- System.out.println("What is your pet's name¿");
- String petName = in.nextLine();
-
- if(petType.equalsIgnoreCase("BabyDuck") || petType.equalsIgnoreCase("Baby Duck")){
- Pet babyDuck = new BabyDucks();
- babyDuck.setName(petName);
- talkingPets.add(babyDuck);
- } else
- if(petType.equalsIgnoreCase("kitty")){
- Pet kitty = new Cat();
- kitty.setName(petName);
- talkingPets.add(kitty);
- } else {
- Pet dog = new Dog();
- dog.setName(petName);
- talkingPets.add(dog);
- }
-
- for(Pet pett: talkingPets){
-
- System.out.println(pett.getName() + "says " + pett.speak() + "¿¿¿");
-
- }
- }
- }
- }
|