|
@@ -1,7 +1,82 @@
|
1
|
1
|
package io.zipcoder.polymorphism;
|
2
|
2
|
|
|
3
|
+import java.util.Scanner;
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* Created by leon on 11/6/17.
|
5
|
7
|
*/
|
6
|
8
|
public class MainApplication {
|
|
9
|
+
|
|
10
|
+ public static void main(String[] args) {
|
|
11
|
+
|
|
12
|
+ String anyPets = "How many pets do you have?";
|
|
13
|
+ int numberOfPets = getNumberOfPets(anyPets);
|
|
14
|
+
|
|
15
|
+ String[] typeOfPet = new String[numberOfPets];
|
|
16
|
+ String[] nameOfPet = new String[numberOfPets];
|
|
17
|
+
|
|
18
|
+ for (int i=0; i < numberOfPets; i++){
|
|
19
|
+ String petType = ("What type of animal is Pet" + (i + 1));
|
|
20
|
+ typeOfPet[i] = getPetType(petType).toLowerCase();
|
|
21
|
+
|
|
22
|
+ String petName = ("What is your " + typeOfPet[i] + "'s name?");
|
|
23
|
+ nameOfPet[i] = getPetName(petName);
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ printResultsNoises(typeOfPet, nameOfPet);
|
|
27
|
+
|
|
28
|
+ }
|
|
29
|
+
|
|
30
|
+ public static int getNumberOfPets(String prompt){
|
|
31
|
+ Scanner userInput = new Scanner(System.in);
|
|
32
|
+ System.out.println(prompt);
|
|
33
|
+ int valueInt = userInput.nextInt();
|
|
34
|
+ return valueInt;
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ public static String getPetType(String prompt){
|
|
38
|
+ Scanner userInput = new Scanner(System.in);
|
|
39
|
+ System.out.println(prompt);
|
|
40
|
+ String valueString = userInput.nextLine();
|
|
41
|
+ return valueString;
|
|
42
|
+
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+ public static String getPetName(String prompt){
|
|
46
|
+ Scanner userInput = new Scanner(System.in);
|
|
47
|
+ System.out.println(prompt);
|
|
48
|
+ String valueString = userInput.nextLine();
|
|
49
|
+ return valueString;
|
|
50
|
+
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ public static void printResults(String[] a, String[] b){
|
|
54
|
+ for (int i=0; i < a.length; i++){
|
|
55
|
+ System.out.print(a[i] + " ");
|
|
56
|
+ System.out.println(b[i]);
|
|
57
|
+ }
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ public static void printResultsNoises(String[] a, String[] b){
|
|
61
|
+ for (int i=0; i < b.length; i++){
|
|
62
|
+ System.out.print(b[i] + " says ");
|
|
63
|
+
|
|
64
|
+ if (a[i].equals("dog")){
|
|
65
|
+ Dog dog = new Dog();
|
|
66
|
+ System.out.println(dog.Speak());
|
|
67
|
+ }
|
|
68
|
+ else if (a[i].equals("cat")){
|
|
69
|
+ Cat cat = new Cat();
|
|
70
|
+ System.out.println(cat.Speak());
|
|
71
|
+ }
|
|
72
|
+ else if (a[i].equals("snake")){
|
|
73
|
+ Snake snake = new Snake();
|
|
74
|
+ System.out.println(snake.Speak());
|
|
75
|
+ }
|
|
76
|
+ else {
|
|
77
|
+ System.out.println("something that I dont understand");
|
|
78
|
+ }
|
|
79
|
+ }
|
|
80
|
+ }
|
|
81
|
+
|
7
|
82
|
}
|