12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import java.util.Scanner;
- /**
- * Created by leon on 11/6/17.
- */
- public class MainApplication {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
-
- System.out.println("Hello! How many pets do you have?");
-
- int numPets = s.nextInt();
- s.nextLine();
- System.out.println("Thank you for telling me.");
-
- Pet[] yourPets = new Pet[numPets];
-
- for (int i = 0; i < numPets; i++) {
- System.out.print("Enter the name of your pet: ");
- String name = s.nextLine();
- System.out.print("What kind of pet is " + name + "? ");
- String type = s.nextLine();
- if (type.equalsIgnoreCase("cat")) {
- yourPets[i] = new Cat(name);
- }
- else if (type.equalsIgnoreCase("dog")) {
- yourPets[i] = new Dog(name);
- }
- else if (type.equalsIgnoreCase("capybara")) {
- yourPets[i] = new Capybara(name);
- }
- else {
- yourPets[i] = new Pet(name);
- }
- }
- System.out.println("Your pets are the following: ");
- for (int i = 0; i < numPets; i++) {
- System.out.println("Your " + yourPets[i].getName() + " says " + yourPets[i].speak());
- }
-
- }
-
- }
|