Browse Source

new changes

Xcuello 5 years ago
parent
commit
511750a455

+ 8
- 0
pom.xml View File

@@ -7,6 +7,14 @@
7 7
     <groupId>io.zipcoder</groupId>
8 8
     <artifactId>polymorphism</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>org.junit.jupiter</groupId>
13
+            <artifactId>junit-jupiter-api</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
 
11 19
 
12 20
 </project>

+ 1
- 0
src/main/java/io/zipcoder/polymorphism/Lion.java View File

@@ -1,6 +1,7 @@
1 1
 package io.zipcoder.polymorphism;
2 2
 
3 3
 public class Lion extends Pet {
4
+
4 5
     public String speak() {
5 6
 
6 7
         return "roar";

+ 2
- 3
src/main/java/io/zipcoder/polymorphism/MainApplication.java View File

@@ -1,8 +1,6 @@
1 1
 package io.zipcoder.polymorphism;
2 2
 
3
-import java.sql.SQLOutput;
4 3
 import java.util.List;
5
-import java.util.Scanner;
6 4
 
7 5
 /**
8 6
  * Created by leon on 11/6/17.
@@ -12,7 +10,7 @@ public class MainApplication {
12 10
 
13 11
     public static void main (String[] args) {
14 12
 
15
-        UserInput ui = new UserInput(); // object instantiation
13
+        UserInput ui = new UserInput();
16 14
 
17 15
         ui.setNumOfPets();
18 16
         ui.setPetNames();
@@ -20,6 +18,7 @@ public class MainApplication {
20 18
         List<Pet> pets = ui.getListOfPets();
21 19
 
22 20
         for (Pet p : pets) {
21
+
23 22
             p.speak();
24 23
             p.getNameOfPet();
25 24
 

+ 2
- 0
src/main/java/io/zipcoder/polymorphism/Pet.java View File

@@ -5,10 +5,12 @@ public abstract class Pet {
5 5
     private String nameOfPet;
6 6
 
7 7
     public String getNameOfPet() {
8
+
8 9
         return nameOfPet;
9 10
     }
10 11
 
11 12
     public void setNameOfPet(String nameOfPet) {
13
+
12 14
         this.nameOfPet = nameOfPet;
13 15
     }
14 16
 

+ 8
- 6
src/main/java/io/zipcoder/polymorphism/UserInput.java View File

@@ -14,6 +14,7 @@ public class UserInput {
14 14
     public void setNumOfPets() {
15 15
 
16 16
         System.out.println("How many pets do you have?");
17
+
17 18
         this.numOfPets = scanner.nextInt();
18 19
     }
19 20
 
@@ -30,16 +31,19 @@ public class UserInput {
30 31
         listOfPets = new ArrayList<Pet>();
31 32
 
32 33
         for (int i = 1; i <= numOfPets; i++) {
34
+
33 35
             System.out.println("What kind of pet is it?");
34 36
             String petType = scanner.next();
35 37
 
36 38
             if (petType.toLowerCase().equals("dog")) {
39
+
37 40
                 pet = new Dog();
38 41
 
39 42
                 System.out.println("what is it's name?");
40 43
                 pet.setNameOfPet(scanner.next());
41 44
                 listOfPets.add(pet);
42 45
             } else if(petType.toLowerCase().equals("cat")) {
46
+
43 47
                 pet = new Cat();
44 48
 
45 49
                 System.out.println("what is it's name?");
@@ -47,21 +51,19 @@ public class UserInput {
47 51
                 listOfPets.add(pet);
48 52
 
49 53
             } else if (petType.toLowerCase().equals("lion")) {
54
+
50 55
                 pet = new Lion();
56
+
51 57
                 System.out.println("what is it's name?");
52 58
                 pet.setNameOfPet(scanner.next());
53 59
                 listOfPets.add(pet);
54 60
             }
55 61
         }
56 62
     }
63
+        public List<Pet> getListOfPets () {
57 64
 
58
-//        public Pet petMaker (String petName){
59
-//
60
-//            return null;
61
-//        }
65
+        return listOfPets;
62 66
 
63
-        public List<Pet> getListOfPets () {
64
-            return listOfPets;
65 67
         }
66 68
 
67 69
     }

+ 2
- 0
src/test/java/io/zipcoder/polymorphism/MainApplicationTest.java View File

@@ -4,4 +4,6 @@ package io.zipcoder.polymorphism;
4 4
  * Created by leon on 11/6/17.
5 5
  */
6 6
 public class MainApplicationTest {
7
+
8
+
7 9
 }