123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /**
- * Created by leon on 11/6/17.
- */
- import java.util.Scanner;
- import java.util.*;
- public class MainApplication {
- private enum petTypes {DOG, CAT, FISH};
-
- public static void Main(String [] args) {
-
- Scanner in = new Scanner(System.in);
- System.out.println("How many pets do you have?");
- int numPet = in.nextInt();
- Pet[] arr = new Pet[numPet];//get size of the array of pets
- for (int i=0;i<numPet;i++){
- System.out.println("What type of pet do you have?");
- String typePet = in.nextLine();
- System.out.println("Name of the pets?");
- String petName = in.nextLine();
- switch (petTypes.valueOf(typePet.toUpperCase())){
- //access enum to get value
- case CAT:
- arr[i] = new Cat(petName);
- break;
- case DOG:
- arr[i] = new Dog(petName);
- break;
- case FISH:
- arr[i] = new Fish(petName);
- break;
- }
- //arr [i] = (typePet + ":" + petName);
- }
- for(Pet i: arr){
-
- System.out.println(i.getName() + ":"+ i.getType() + "says" + i.speak());
- }
- //String output = Arrays.toString(arr);
-
- }
-
-
- }
-
- /*System.out.println("What pets do you have?");
- String petType = in.nextLine();
- if (numPet == 1){
- System.out.println();
- else if (numPet >1)
- {
-
- }
- }
-
- System.out.println("What are their name?");
- */
|