|
@@ -1,7 +1,88 @@
|
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
|
+ Scanner scanner = new Scanner(System.in);
|
|
13
|
+ StringBuilder builder1 = new StringBuilder();
|
|
14
|
+ StringBuilder builder2 = new StringBuilder();
|
|
15
|
+
|
|
16
|
+ String typeOfPet = "";
|
|
17
|
+ String nameOfPet = "";
|
|
18
|
+
|
|
19
|
+ System.out.println("How many pets do you currently own? You can include your kids as well! :)");
|
|
20
|
+ int numberOfPets = Integer.parseInt(scanner.nextLine());
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+ for (int i = 0; i < numberOfPets; i++) {
|
|
24
|
+ typeOfPet = scanner.nextLine();
|
|
25
|
+ builder1.append(typeOfPet);
|
|
26
|
+ if (i < numberOfPets) {
|
|
27
|
+ System.out.println("Do you have more pets? If so what kind is the next?");
|
|
28
|
+ builder1.append(", ");
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+ System.out.println("What's the first one's name?");
|
|
33
|
+
|
|
34
|
+ for (int j = 0; j < i; j++) {
|
|
35
|
+ nameOfPet = scanner.nextLine();
|
|
36
|
+ builder2.append(nameOfPet);
|
|
37
|
+ if (j < numberOfPets) {
|
|
38
|
+ System.out.println("Do you have more pets? If so what kind is the next?");
|
|
39
|
+ builder2.append(", ");
|
|
40
|
+
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+ System.out.println(builder1.toString());
|
|
46
|
+ System.out.println(builder2.toString());
|
|
47
|
+
|
|
48
|
+ String[] petNameArray = builder2.toString().split(", ");
|
|
49
|
+ String[] petKindArray = builder1.toString().split(", ");
|
|
50
|
+
|
|
51
|
+ for (int k = 0; k < numberOfPets; k++) {
|
|
52
|
+ Dog dog = new Dog(petNameArray[k]);
|
|
53
|
+ Cat cat = new Cat(petNameArray[k]);
|
|
54
|
+ String sounds = "";
|
|
55
|
+
|
|
56
|
+ if (petKindArray[k].equals("cat")) {
|
|
57
|
+ sounds = cat.speak();
|
|
58
|
+ } else if (petKindArray[k].equals("dog")) {
|
|
59
|
+ sounds = dog.speak();
|
|
60
|
+ } else {
|
|
61
|
+ sounds = "White Noise!!!";
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+ }
|
|
65
|
+ }
|
7
|
66
|
}
|
|
67
|
+
|
|
68
|
+// public class Pet {
|
|
69
|
+// public void Speak(){
|
|
70
|
+// //String sound
|
|
71
|
+// //System.out.println(sound);
|
|
72
|
+// }
|
|
73
|
+// }
|
|
74
|
+//
|
|
75
|
+// public class Dog extends Pet{
|
|
76
|
+// String sound = "Woof Woof";
|
|
77
|
+// }
|
|
78
|
+//
|
|
79
|
+// public class Cat extends Pet{
|
|
80
|
+// String sound = "Meow Meow";
|
|
81
|
+// }
|
|
82
|
+//
|
|
83
|
+// public class Pig extends Pet{
|
|
84
|
+// String sound = "Oink Oink";
|
|
85
|
+// }
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|