diff --git a/pom.xml b/pom.xml
index d73c078..7f00e80 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,18 @@
io.zipcoder
Interfaces
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 1.8
+ 1.8
+
+
+
+
diff --git a/src/main/java/io/zipcoder/Application.java b/src/main/java/io/zipcoder/Application.java
index 3a257cb..b032e4e 100644
--- a/src/main/java/io/zipcoder/Application.java
+++ b/src/main/java/io/zipcoder/Application.java
@@ -1,5 +1,59 @@
package io.zipcoder;
+import java.util.ArrayList;
+import java.util.Scanner;
public class Application {
+
+ public ArrayList collectionOfPets = new ArrayList<>();
+
+ Scanner scan = new Scanner(System.in);
+
+ public void userDataOfPets(){
+ System.out.println("How many pets do you have?");
+ int numberOfPets = (Integer.valueOf(scan.nextLine()));
+ for (int i = 0; i < numberOfPets; i++){
+ String name;
+ String petType;
+ System.out.println("What is the name of pet " + (i +1) +" ?");
+ name = scan.nextLine();
+ System.out.println("What kind of pet is it "+ (i +1) +" ?");
+ petType = scan.nextLine();
+ addPet(name, petType);
+
+ }
+ }
+ public void addPet(String petName, String petType) {
+ Pet pet = null;
+ if (petType.equalsIgnoreCase("Dog")) {
+ collectionOfPets.add(new Dog(petName));
+
+ } else if (petType.equalsIgnoreCase("Cat")) {
+ collectionOfPets.add(new Cat(petName));
+ } else if (petType.equalsIgnoreCase("Unicorn")) {
+ collectionOfPets.add(new Unicorn(petName));
+ } else {
+ pet = null;
+ }
+
+ }
+ public String printList() {
+ StringBuilder sb = new StringBuilder();
+ for (Pet pet : collectionOfPets) {
+ sb.append(pet.getName());
+ sb.append(" ");
+ sb.append(pet.getClass().getSimpleName());
+ sb.append(", ");
+
+ }
+ return String.valueOf(sb);
+ }
+
+
+
+ public static void main(String[] args) {
+ Application application = new Application();
+ application.userDataOfPets();
+ application.printList();
+ }
}
diff --git a/src/main/java/io/zipcoder/Cat.java b/src/main/java/io/zipcoder/Cat.java
new file mode 100644
index 0000000..2aa7891
--- /dev/null
+++ b/src/main/java/io/zipcoder/Cat.java
@@ -0,0 +1,18 @@
+package io.zipcoder;
+
+public class Cat extends Pet {
+ private String petName;
+
+ public Cat(String petName) {
+ this.petName = petName;
+ }
+
+ public String getName() {
+ return this.petName;
+ }
+
+ @Override
+ public String speak() {
+ return "meow";
+ }
+}
diff --git a/src/main/java/io/zipcoder/Dog.java b/src/main/java/io/zipcoder/Dog.java
new file mode 100644
index 0000000..7b0fe49
--- /dev/null
+++ b/src/main/java/io/zipcoder/Dog.java
@@ -0,0 +1,19 @@
+package io.zipcoder;
+
+public class Dog extends Pet {
+
+ private String petName;
+
+ public Dog(String petName) {
+ this.petName = petName;
+ }
+
+ public String getName() {
+ return this.petName;
+ }
+
+ @Override
+ public String speak() {
+ return "woof";
+ }
+}
diff --git a/src/main/java/io/zipcoder/Pet.java b/src/main/java/io/zipcoder/Pet.java
new file mode 100644
index 0000000..7332910
--- /dev/null
+++ b/src/main/java/io/zipcoder/Pet.java
@@ -0,0 +1,36 @@
+package io.zipcoder;
+
+
+import java.util.Comparator;
+
+public abstract class Pet implements Comparable {
+
+ private String petName;
+
+ public abstract String speak();
+
+ public String getName() {
+ return petName;
+ }
+
+ public void setPetName(String petName) {
+ this.petName = petName;
+ }
+
+
+ public int compareTo(Pet o) {
+ int compare = this.getName().compareTo(o.getName());
+ int compareClass = this.getClass().getSimpleName().compareTo(o.getClass().getSimpleName());
+ if (compare == 0) {
+ return compareClass;
+ }
+
+ return compare;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString();
+ }
+
+}
diff --git a/src/main/java/io/zipcoder/PetCompare.java b/src/main/java/io/zipcoder/PetCompare.java
new file mode 100644
index 0000000..27550e1
--- /dev/null
+++ b/src/main/java/io/zipcoder/PetCompare.java
@@ -0,0 +1,13 @@
+package io.zipcoder;
+
+import java.util.Comparator;
+
+public class PetCompare implements Comparator {
+
+ public int compare(Pet o1, Pet o2) {
+ int compare = o1.getClass().getSimpleName().compareToIgnoreCase(o2.getClass().getSimpleName());
+ if(compare != 0) {
+ return o1.getName().compareToIgnoreCase(o1.getName());
+ }
+ return compare;
+ }}
diff --git a/src/main/java/io/zipcoder/Unicorn.java b/src/main/java/io/zipcoder/Unicorn.java
new file mode 100644
index 0000000..becb905
--- /dev/null
+++ b/src/main/java/io/zipcoder/Unicorn.java
@@ -0,0 +1,23 @@
+package io.zipcoder;
+
+public class Unicorn extends Pet {
+ private String petName;
+
+ public Unicorn(String petName) {
+ this.petName = petName;
+
+ }
+
+ public String getName() {
+
+ return this.petName;
+ }
+
+
+ @Override
+ public String speak() {
+ return "sparkles glitter";
+ }
+
+
+}
diff --git a/src/test/java/io/zipcoder/ApplicationTest.java b/src/test/java/io/zipcoder/ApplicationTest.java
index b744df5..a04775c 100644
--- a/src/test/java/io/zipcoder/ApplicationTest.java
+++ b/src/test/java/io/zipcoder/ApplicationTest.java
@@ -1,5 +1,45 @@
package io.zipcoder;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
public class ApplicationTest {
-}
+
+ @Test
+ public void userDataOfPets() {
+ }
+
+ @Test
+ public void addPet() {
+ //Given
+ Application application = new Application();
+ //When
+ application.addPet("Hugo", "Dog");
+ String expected = "Hugo Dog, ";
+ String actual = application.printList();
+ //Then
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void printListTest() {
+ //Given
+ Application application = new Application();
+
+ //When
+ application.addPet("Hugo", "Dog");
+ application.addPet("Bob", "Cat");
+
+ String expected = "Hugo Dog, Bob Cat, ";
+ String actual = application.printList();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/CatTest.java b/src/test/java/io/zipcoder/CatTest.java
new file mode 100644
index 0000000..de50e84
--- /dev/null
+++ b/src/test/java/io/zipcoder/CatTest.java
@@ -0,0 +1,37 @@
+package io.zipcoder;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class CatTest {
+
+
+ @Test
+ public void speakTest() {
+ //Given
+ Cat cat = new Cat("Sammy");
+
+ //When
+ String expected = "meow";
+ String actual = cat.speak();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void setNameTest() {
+ //Given
+ Cat cat = new Cat("Kitty");
+
+ //When
+ String expected = "Kitty";
+ cat.setPetName(expected);
+ String actual = cat.getName();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/DogTest.java b/src/test/java/io/zipcoder/DogTest.java
new file mode 100644
index 0000000..441aa6b
--- /dev/null
+++ b/src/test/java/io/zipcoder/DogTest.java
@@ -0,0 +1,37 @@
+package io.zipcoder;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class DogTest {
+
+
+ @Test
+ public void speakTest() {
+ //Given
+ Dog dog = new Dog("Spike");
+
+ //When
+ String expected = "woof";
+ String actual = dog.speak();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void setNameTest() {
+ //Given
+ Dog dog = new Dog("Sally");
+
+ //When
+ String expected = "Sally";
+ dog.setPetName(expected);
+ String actual = dog.getName();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/PetTest.java b/src/test/java/io/zipcoder/PetTest.java
new file mode 100644
index 0000000..796b73c
--- /dev/null
+++ b/src/test/java/io/zipcoder/PetTest.java
@@ -0,0 +1,78 @@
+package io.zipcoder;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+
+import static org.junit.Assert.*;
+
+public class PetTest {
+
+ @Test
+ public void setNameTest() {
+ //Given
+ Dog dog = new Dog("Molly");
+
+ //When
+ String expected = "Molly";
+ dog.setPetName(expected);
+ String actual = dog.getName();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void compareToTest() {
+ //Given
+ ArrayList tempList = new ArrayList<>();
+ Dog bun = new Dog("Bun");
+ Dog mun = new Dog("Mun");
+ Cat fun = new Cat("Fun");
+ Cat hun = new Cat("Hun");
+ Unicorn run = new Unicorn("Run");
+
+ tempList.add(bun);
+ tempList.add(mun);
+ tempList.add(fun);
+ tempList.add(hun);
+ tempList.add(run);
+
+ //When
+ Pet[] expected = {bun, fun, hun, mun, run};
+ Collections.sort(tempList);
+ Pet[] actual = tempList.toArray(new Pet[tempList.size()]);
+
+ //When
+ Assert.assertTrue(Arrays.equals(expected,actual));
+
+ }
+
+ @Test
+ public void compareTest(){
+ //Given
+ Application app = new Application();
+
+ Dog bun = new Dog("Bun");
+ Cat fun = new Cat("Fun");
+ Unicorn run = new Unicorn("Run");
+ Unicorn sun = new Unicorn("Sun");
+
+ app.collectionOfPets.add(bun);
+ app.collectionOfPets.add(fun);
+ app.collectionOfPets.add(run);
+ app.collectionOfPets.add(sun);
+
+ //When
+ Collections.sort(app.collectionOfPets,new PetCompare());
+ Pet[] expected = {bun, fun, run, sun};
+ Pet[] actual = app.collectionOfPets.toArray(new Pet[app.collectionOfPets.size()]);
+
+ //When
+ Assert.assertTrue(Arrays.equals(expected,actual));
+
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/io/zipcoder/UnicornTest.java b/src/test/java/io/zipcoder/UnicornTest.java
new file mode 100644
index 0000000..b67dfcf
--- /dev/null
+++ b/src/test/java/io/zipcoder/UnicornTest.java
@@ -0,0 +1,37 @@
+package io.zipcoder;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class UnicornTest {
+
+
+ @Test
+ public void speakTest() {
+ //Given
+ Unicorn unicorn = new Unicorn("Shine");
+
+ //When
+ String expected = "sparkles glitter";
+ String actual = unicorn.speak();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void setNameTest() {
+ //Given
+ Unicorn unicorn = new Unicorn("Rainbow");
+
+ //When
+ String expected = "Rainbow";
+ unicorn.setPetName(expected);
+ String actual = unicorn.getName();
+
+ //Then
+ Assert.assertEquals(expected, actual);
+ }
+}
\ No newline at end of file