12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import java.util.*;
-
- public class MainApplication {
-
- enum petTypes {CAT, DOG, FISH};
-
- public static void main(String[] args){
-
- Scanner scan = new Scanner(System.in);
-
- System.out.println("How many pets do you have?");
- int numberOfPets = scan.nextInt();
- scan.nextLine();
-
- Pet[] petArr = new Pet[numberOfPets];
-
- for(int i = 0; i < numberOfPets; i++){
-
- System.out.println("What type of pet?");
- String typeOfPet = scan.nextLine();
-
- System.out.println("Name?");
- String namePet = scan.nextLine();
-
- switch(petTypes.valueOf(typeOfPet.toUpperCase())){
-
- case CAT:
- petArr[i] = new Cat(namePet);
- break;
-
- case DOG:
- petArr[i] = new Dog(namePet);
- break;
-
- case FISH:
- petArr[i] = new Fish(namePet);
- break;
-
- }
-
- }
-
- for(Pet i : petArr){
-
- System.out.println
- (i.getType() + " : " + i.getName() + " says: " + i.setSpeak());
-
- }
- }
- }
-
|