|
@@ -0,0 +1,67 @@
|
|
1
|
+package io.zipcoder.polymorphism;
|
|
2
|
+
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.List;
|
|
5
|
+import java.util.Scanner;
|
|
6
|
+
|
|
7
|
+public class UserInput {
|
|
8
|
+
|
|
9
|
+ List<Pet> listOfPets;
|
|
10
|
+ Scanner scanner = new Scanner(System.in);
|
|
11
|
+
|
|
12
|
+ private int numOfPets;
|
|
13
|
+
|
|
14
|
+ public void setNumOfPets() {
|
|
15
|
+
|
|
16
|
+ System.out.println("How many pets do you have?");
|
|
17
|
+ this.numOfPets = scanner.nextInt();
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ public int getNumOfPets() {
|
|
21
|
+
|
|
22
|
+ return numOfPets;
|
|
23
|
+
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ public void setPetNames() {
|
|
27
|
+
|
|
28
|
+ Pet pet;
|
|
29
|
+
|
|
30
|
+ listOfPets = new ArrayList<Pet>();
|
|
31
|
+
|
|
32
|
+ for (int i = 1; i <= numOfPets; i++) {
|
|
33
|
+ System.out.println("What kind of pet is it?");
|
|
34
|
+ String petType = scanner.next();
|
|
35
|
+
|
|
36
|
+ if (petType.toLowerCase().equals("dog")) {
|
|
37
|
+ pet = new Dog();
|
|
38
|
+
|
|
39
|
+ System.out.println("what is it's name?");
|
|
40
|
+ pet.setNameOfPet(scanner.next());
|
|
41
|
+ listOfPets.add(pet);
|
|
42
|
+ } else if(petType.toLowerCase().equals("cat")) {
|
|
43
|
+ pet = new Cat();
|
|
44
|
+
|
|
45
|
+ System.out.println("what is it's name?");
|
|
46
|
+ pet.setNameOfPet(scanner.next());
|
|
47
|
+ listOfPets.add(pet);
|
|
48
|
+
|
|
49
|
+ } else if (petType.toLowerCase().equals("lion")) {
|
|
50
|
+ pet = new Lion();
|
|
51
|
+ System.out.println("what is it's name?");
|
|
52
|
+ pet.setNameOfPet(scanner.next());
|
|
53
|
+ listOfPets.add(pet);
|
|
54
|
+ }
|
|
55
|
+ }
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+// public Pet petMaker (String petName){
|
|
59
|
+//
|
|
60
|
+// return null;
|
|
61
|
+// }
|
|
62
|
+
|
|
63
|
+ public List<Pet> getListOfPets () {
|
|
64
|
+ return listOfPets;
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ }
|