diff --git a/pom.xml b/pom.xml
index d73c078..8423c81 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,18 @@
io.zipcoder
Interfaces
1.0-SNAPSHOT
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ 8
+ 8
+
+
+
+
diff --git a/src/main/java/io/zipcoder/Application.java b/src/main/java/io/zipcoder/Application.java
deleted file mode 100644
index 3a257cb..0000000
--- a/src/main/java/io/zipcoder/Application.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package io.zipcoder;
-
-
-public class Application {
-}
diff --git a/src/main/java/io/zipcoder/pets/Cat.java b/src/main/java/io/zipcoder/pets/Cat.java
new file mode 100644
index 0000000..7ca9a2c
--- /dev/null
+++ b/src/main/java/io/zipcoder/pets/Cat.java
@@ -0,0 +1,12 @@
+package io.zipcoder.pets;
+
+public class Cat extends Pets {
+
+ public Cat(String name) {
+ super(name, "cat");
+ }
+
+ public String speak() {
+ return "Mow mow...";
+ }
+}
diff --git a/src/main/java/io/zipcoder/pets/Dog.java b/src/main/java/io/zipcoder/pets/Dog.java
new file mode 100644
index 0000000..24d9856
--- /dev/null
+++ b/src/main/java/io/zipcoder/pets/Dog.java
@@ -0,0 +1,11 @@
+package io.zipcoder.pets;
+
+public class Dog extends Pets {
+
+ public Dog(String name){
+ super(name, "dog");
+ }
+ public String speak() {
+ return "Wooooooof!";
+ }
+}
diff --git a/src/main/java/io/zipcoder/pets/Fish.java b/src/main/java/io/zipcoder/pets/Fish.java
new file mode 100644
index 0000000..6432ed1
--- /dev/null
+++ b/src/main/java/io/zipcoder/pets/Fish.java
@@ -0,0 +1,12 @@
+package io.zipcoder.pets;
+
+public class Fish extends Pets{
+
+ public Fish(String name){
+ super(name,"fish");
+ }
+
+ public String speak() {
+ return "Glub glub...";
+ }
+}
diff --git a/src/main/java/io/zipcoder/pets/Pets.java b/src/main/java/io/zipcoder/pets/Pets.java
new file mode 100644
index 0000000..88e0a1f
--- /dev/null
+++ b/src/main/java/io/zipcoder/pets/Pets.java
@@ -0,0 +1,34 @@
+package io.zipcoder.pets;
+
+public abstract class Pets {
+ private String name;
+ private String type;
+
+
+ public Pets(String name, String type){
+ this.name = name;
+ this.type = type;
+ }
+
+ public String name(){
+ return name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getType() { return type; }
+
+ public void setType(String type) { this.type = type; }
+
+ abstract public String speak();
+
+
+
+}
+
diff --git a/src/main/java/io/zipcoder/utils/Application.java b/src/main/java/io/zipcoder/utils/Application.java
new file mode 100644
index 0000000..eaa3bde
--- /dev/null
+++ b/src/main/java/io/zipcoder/utils/Application.java
@@ -0,0 +1,35 @@
+package io.zipcoder.utils;
+
+import io.zipcoder.Console;
+import io.zipcoder.pets.Pets;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+/**
+ * Created by leon on 11/6/17.
+ */
+public class Application {
+ public static void main(String[] args) {
+ petApp();
+ }
+ public static void petApp() {
+ Integer numofPets = getNumOfPets();
+ Console.println("TELL ME MORE... \n", numofPets);
+
+ String[] petTypes = new String[numofPets];
+ String[] petNames = new String[numofPets];
+ for(int i = 0; i < numofPets; i++){
+ petNames[i] = Console.getStringInput(String.format("Tell me the name of pet %s ...\n", i+1));
+ petTypes[i] = Console.getStringInput(String.format("Ooh... what KIND of pet is %s ... \n", petNames[i]));
+ }
+ PetLodge cozy = new PetLodge(numofPets, petNames, petTypes);
+ cozy.displayPetInfo();
+ }
+
+ protected static Integer getNumOfPets() {
+ return Console.getIntegerInput("I'm Kai! I have a cat named Boots. How many pets do you have?\n");
+ }
+
+
+}
diff --git a/src/main/java/io/zipcoder/utils/Console.java b/src/main/java/io/zipcoder/utils/Console.java
new file mode 100644
index 0000000..8f74d51
--- /dev/null
+++ b/src/main/java/io/zipcoder/utils/Console.java
@@ -0,0 +1,29 @@
+package io.zipcoder;
+
+import java.util.Scanner;
+
+public class Console {
+
+ public static void print(String output, Object... args) {
+ System.out.printf(output, args);
+ }
+
+ public static void println(String output, Object... args) {
+ print(output + "\n", args);
+ }
+
+ public static String getStringInput(String prompt) {
+ Scanner scanner = new Scanner(System.in);
+ print(prompt);
+ String userInput = scanner.nextLine();
+ return userInput;
+ }
+
+ public static Integer getIntegerInput(String prompt) {
+ Scanner scanner = new Scanner(System.in);
+ print(prompt);
+ Integer userInput = Integer.valueOf(scanner.nextLine());
+ return userInput;
+ }
+}
+
diff --git a/src/main/java/io/zipcoder/utils/PetLodge.java b/src/main/java/io/zipcoder/utils/PetLodge.java
new file mode 100644
index 0000000..d48cd6a
--- /dev/null
+++ b/src/main/java/io/zipcoder/utils/PetLodge.java
@@ -0,0 +1,66 @@
+package io.zipcoder.utils;
+
+import io.zipcoder.Console;
+import io.zipcoder.pets.Cat;
+import io.zipcoder.pets.Dog;
+import io.zipcoder.pets.Fish;
+import io.zipcoder.pets.Pets;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collections;
+
+public class PetLodge {
+
+ public PetLodge() {}
+ private Pets[] pets;
+ private static ArrayList listOPets = new ArrayList();
+
+ public PetLodge(Integer numOfPets, String[] petNames, String[] petTypes){
+ this.pets = createPets(numOfPets, petNames, petTypes);
+ }
+
+ public Pets[] createPets(Integer numOfPets, String[] petNames, String[] petTypes){
+ Pets[] pets = new Pets[numOfPets];
+ for(int i = 0; i < numOfPets; i++){
+ pets[i] = createPetFromType(petNames[i], petTypes[i]);
+ }
+ return pets;
+ }
+
+ public Pets createPetFromType(String petName, String petType) {
+ Pets pet;
+ if (petType.equals("dog")) {
+ pet = new Dog(petName);
+ }
+ else if (petType.equals("cat")) {
+ pet = new Cat(petName);
+ }
+ else if (petType.equals("fish")) {
+ pet = new Fish(petName);
+ }
+ else{
+ pet = new Fish(petName);
+ }
+ return pet;
+ }
+
+ public void displayPetInfo(){
+ Console.println("You got %s pets!", pets.length);
+
+ for(int i = 0; i< pets.length; i++){
+ Console.println("Pet %s is a %s named %s! %s", i+1, pets[i].getType(), pets[i].getName(), pets[i].speak());
+
+ }
+ sortTypeBeforeName(listOPets);
+ }
+ public static ArrayList sortTypeBeforeName(ArrayList pets) {
+ Collections.sort(pets, new PetTypeSorting());
+ Collections.sort(pets, new PetNameSorting());
+ return pets;
+ }
+ public Pets[] getPets() {
+ return this.pets;
+ }
+
+}
diff --git a/src/main/java/io/zipcoder/utils/PetNameSorting.java b/src/main/java/io/zipcoder/utils/PetNameSorting.java
new file mode 100644
index 0000000..111ad44
--- /dev/null
+++ b/src/main/java/io/zipcoder/utils/PetNameSorting.java
@@ -0,0 +1,11 @@
+package io.zipcoder.utils;
+
+import io.zipcoder.pets.Pets;
+
+import java.util.Comparator;
+
+public class PetNameSorting implements Comparator {
+ public int compare(Pets p1, Pets p2) {
+ return p1.getName().compareTo(p2.getName());
+ }
+}
diff --git a/src/main/java/io/zipcoder/utils/PetTypeSorting.java b/src/main/java/io/zipcoder/utils/PetTypeSorting.java
new file mode 100644
index 0000000..673870a
--- /dev/null
+++ b/src/main/java/io/zipcoder/utils/PetTypeSorting.java
@@ -0,0 +1,12 @@
+package io.zipcoder.utils;
+
+import io.zipcoder.pets.Pets;
+
+import java.util.Comparator;
+
+public class PetTypeSorting implements Comparator {
+
+ public int compare(Pets p1, Pets p2) {
+ return p1.getType().compareTo(p2.getType());
+ }
+}
diff --git a/src/test/java/io/zipcoder/pets/CatTest.java b/src/test/java/io/zipcoder/pets/CatTest.java
new file mode 100644
index 0000000..96aee9f
--- /dev/null
+++ b/src/test/java/io/zipcoder/pets/CatTest.java
@@ -0,0 +1,42 @@
+package io.zipcoder.pets;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class CatTest {
+ @Test
+ public void speak1() {
+ Cat cat = new Cat("Yelp");
+ String actual = cat.speak();
+ String expected = "Mow mow...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void speak2() {
+ Cat cat = new Cat("Paul");
+ String actual = cat.speak();
+ String expected = "Mow mow...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void speak3() {
+ Cat cat = new Cat("Opal");
+ String actual = cat.speak();
+ String expected = "Mow mow...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void dogNameConstructorTest() {
+ Cat cat = new Cat("Ovard");
+ Assert.assertEquals("Ovard", cat.getName());
+ }
+ @Test
+ public void dogTypeConstructorTest() {
+ Cat cat = new Cat("Pumpkin");
+ Assert.assertEquals("cat", cat.getType());
+ }
+
+}
diff --git a/src/test/java/io/zipcoder/pets/DogTest.java b/src/test/java/io/zipcoder/pets/DogTest.java
new file mode 100644
index 0000000..601467a
--- /dev/null
+++ b/src/test/java/io/zipcoder/pets/DogTest.java
@@ -0,0 +1,42 @@
+package io.zipcoder.pets;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DogTest {
+ @Test
+ public void speak1() {
+ Dog doge = new Dog("Bobert");
+ String actual = doge.speak();
+ String expected = "Wooooooof!";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void speak2() {
+ Dog doge = new Dog("Harold");
+ String actual = doge.speak();
+ String expected = "Wooooooof!";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void speak3() {
+ Dog doge = new Dog("Mary");
+ String actual = doge.speak();
+ String expected = "Wooooooof!";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void dogNameConstructorTest() {
+ Dog doge = new Dog("Bob");
+ Assert.assertEquals("Bob", doge.getName());
+ }
+ @Test
+ public void dogTypeConstructorTest() {
+ Dog doge = new Dog("Bob");
+ Assert.assertEquals("dog", doge.getType());
+ }
+
+}
diff --git a/src/test/java/io/zipcoder/pets/FishTest.java b/src/test/java/io/zipcoder/pets/FishTest.java
new file mode 100644
index 0000000..1da3f82
--- /dev/null
+++ b/src/test/java/io/zipcoder/pets/FishTest.java
@@ -0,0 +1,43 @@
+package io.zipcoder.pets;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class FishTest {
+ @Test
+ public void speak1() {
+ Fish fsh = new Fish("Yellow");
+ String actual = fsh.speak();
+ String expected = "Glub glub...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void speak2() {
+ Fish fsh = new Fish("Pail");
+ String actual = fsh.speak();
+ String expected = "Glub glub...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void speak3() {
+ Fish fsh = new Fish("Martin");
+ String actual = fsh.speak();
+ String expected = "Glub glub...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void dogNameConstructorTest() {
+ Fish doge = new Fish("Bob");
+ Assert.assertEquals("Bob", doge.getName());
+ }
+ @Test
+ public void dogTypeConstructorTest() {
+ Fish doge = new Fish("Eagle");
+ Assert.assertEquals("fish", doge.getType());
+ }
+
+}
diff --git a/src/test/java/io/zipcoder/pets/PetsTest.java b/src/test/java/io/zipcoder/pets/PetsTest.java
new file mode 100644
index 0000000..c8ca01a
--- /dev/null
+++ b/src/test/java/io/zipcoder/pets/PetsTest.java
@@ -0,0 +1,80 @@
+package io.zipcoder.pets;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PetsTest {
+ @Test
+ public void getNameTest1() {
+ Dog doge = new Dog("Unicycle");
+ doge.setName("Bicycle");
+ String actual = doge.getName();
+ String expected = "Bicycle";
+ Assert.assertEquals(expected, actual);
+ }
+ @Test
+ public void getNameTest2() {
+ Dog doge = new Dog("Beebo");
+ doge.setName("Orange");
+ String actual = doge.getName();
+ String expected = "Orange";
+ Assert.assertEquals(expected, actual);
+ }
+ @Test
+ public void getNameTest3() {
+ Dog doge = new Dog("Beebo");
+ doge.setName("Corg");
+ String actual = doge.getName();
+ String expected = "Orange";
+ Assert.assertNotEquals(expected, actual);
+ }
+
+ @Test
+ public void getTypeTest1() {
+ Cat cat = new Cat("Fred");
+ cat.setType("Froilan");
+ String actual = cat.getType();
+ String expected = "Froilan";
+ Assert.assertEquals(expected, actual);
+ }
+ @Test
+ public void getTypeTest2() {
+ Cat cat = new Cat("Doc");
+ cat.setType("cat");
+ String actual = cat.getType();
+ String expected = "cat";
+ Assert.assertEquals(expected, actual);
+ }
+ @Test
+ public void getTypeTest3() {
+ Dog doge = new Dog("Unicycle");
+ doge.setType("dog");
+ String actual = doge.getType();
+ String expected = "dog";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void petSpeak1() {
+ Dog doge = new Dog("Yeller");
+ String actual = doge.speak();
+ String expected = "Wooooooof!";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void petSpeak2() {
+ Cat cat = new Cat("Jenkins");
+ String actual = cat.speak();
+ String expected = "Mow mow...";
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void petSpeak3() {
+ Fish fish = new Fish("Ribbers");
+ String actual = fish.speak();
+ String expected = "Glub glub...";
+ Assert.assertEquals(expected, actual);
+ }
+}
diff --git a/src/test/java/io/zipcoder/ApplicationTest.java b/src/test/java/io/zipcoder/utils/ApplicationTest.java
similarity index 56%
rename from src/test/java/io/zipcoder/ApplicationTest.java
rename to src/test/java/io/zipcoder/utils/ApplicationTest.java
index b744df5..d4f9469 100644
--- a/src/test/java/io/zipcoder/ApplicationTest.java
+++ b/src/test/java/io/zipcoder/utils/ApplicationTest.java
@@ -1,4 +1,4 @@
-package io.zipcoder;
+package io.zipcoder.utils;
public class ApplicationTest {
diff --git a/src/test/java/io/zipcoder/utils/PetLodgeTest.java b/src/test/java/io/zipcoder/utils/PetLodgeTest.java
new file mode 100644
index 0000000..67914ca
--- /dev/null
+++ b/src/test/java/io/zipcoder/utils/PetLodgeTest.java
@@ -0,0 +1,126 @@
+package io.zipcoder.utils;
+
+import io.zipcoder.pets.Cat;
+import io.zipcoder.pets.Dog;
+import io.zipcoder.pets.Fish;
+import io.zipcoder.pets.Pets;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PetLodgeTest {
+ @Test
+ public void createPetFromTypeTest1(){
+ //given
+ PetLodge cozy = new PetLodge();
+ String petName = "bobert";
+ String petType = "cat";
+ //when
+ Pets actual = cozy.createPetFromType(petName, petType);
+ //then
+ Assert.assertTrue(actual instanceof Cat);
+ }
+
+ @Test
+ public void createPetFromTypeTest2(){
+ //given
+ PetLodge cozy = new PetLodge();
+ String petName = "beebo";
+ String petType = "dog";
+ //when
+ Pets actual = cozy.createPetFromType(petName, petType);
+ //then
+ Assert.assertTrue(actual instanceof Dog);
+ }
+
+ @Test
+ public void createPetFromTypeTest3(){
+ //given
+ PetLodge cozy = new PetLodge();
+ String petName = "bobert";
+ String petType = "fish";
+ //when
+ Pets actual = cozy.createPetFromType(petName, petType);
+ //then
+ Assert.assertTrue(actual instanceof Fish);
+ }
+
+ @Test
+ public void createPetsTest1(){
+ String[] petType = {"dog", "cat", "fish"};
+ String[] petName = {"Petto", "Marvin", "Peanut"};
+ Integer numOfPets = 3;
+ PetLodge cozy = new PetLodge();
+ Pets[] actual = cozy.createPets(numOfPets, petName, petType);
+ Assert.assertEquals(3, actual.length);
+ for(int i = 0; i < actual.length; i++){
+ Assert.assertEquals(petName[i], actual[i].getName());
+ Assert.assertEquals(petType[i], actual[i].getType());
+ }
+ }
+ @Test
+ public void createPetsTest2(){
+ String[] petType = {"dog", "cat", "fish"};
+ String[] petName = {"Mark", "Beep", "Jarvis"};
+ Integer numOfPets = 3;
+ PetLodge cozy = new PetLodge();
+ Pets[] actual = cozy.createPets(numOfPets, petName, petType);
+ Assert.assertEquals(3, actual.length);
+ for(int i = 0; i < actual.length; i++){
+ Assert.assertEquals(petName[i], actual[i].getName());
+ Assert.assertEquals(petType[i], actual[i].getType());
+ }
+ }
+ @Test
+ public void createPetsTest3(){
+ String[] petType = {"dog", "cat", "fish"};
+ String[] petName = {"Bob", "Man", "Orange"};
+ Integer numOfPets = 3;
+ PetLodge cozy = new PetLodge();
+ Pets[] actual = cozy.createPets(numOfPets, petName, petType);
+ Assert.assertEquals(3, actual.length);
+ for(int i = 0; i < actual.length; i++){
+ Assert.assertEquals(petName[i], actual[i].getName());
+ Assert.assertEquals(petType[i], actual[i].getType());
+ }
+ }
+ @Test
+ public void constructorTest1() {
+ String[] petType = {"dog", "cat", "fish"};
+ String[] petName = {"Bob", "Man", "Orange"};
+ Integer numOfPets = 3;
+ PetLodge cozy = new PetLodge(numOfPets, petName, petType);
+ Pets[] actual = cozy.getPets();
+ Assert.assertEquals(3, actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ Assert.assertEquals(petName[i], actual[i].getName());
+ Assert.assertEquals(petType[i], actual[i].getType());
+ }
+ }
+ @Test
+ public void constructorTest2() {
+ String[] petType = {"dog", "cat", "fish"};
+ String[] petName = {"Oval", "ManChild", "Umbrella"};
+ Integer numOfPets = 3;
+ PetLodge cozy = new PetLodge(numOfPets, petName, petType);
+ Pets[] actual = cozy.getPets();
+ Assert.assertEquals(3, actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ Assert.assertEquals(petName[i], actual[i].getName());
+ Assert.assertEquals(petType[i], actual[i].getType());
+ }
+ }
+ @Test
+ public void constructorTest3() {
+ String[] petType = {"dog", "cat", "fish"};
+ String[] petName = {"Boot", "Marble", "Pint"};
+ Integer numOfPets = 3;
+ PetLodge cozy = new PetLodge(numOfPets, petName, petType);
+ Pets[] actual = cozy.getPets();
+ Assert.assertEquals(3, actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ Assert.assertEquals(petName[i], actual[i].getName());
+ Assert.assertEquals(petType[i], actual[i].getType());
+ }
+ }
+}
+