diff --git a/pom.xml b/pom.xml
index d73c078..58539bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,5 +15,10 @@
4.12
test
+
+ junit
+ junit
+ RELEASE
+
diff --git a/src/main/java/io/zipcoder/Animal.java b/src/main/java/io/zipcoder/Animal.java
new file mode 100644
index 0000000..fddfab8
--- /dev/null
+++ b/src/main/java/io/zipcoder/Animal.java
@@ -0,0 +1,5 @@
+package io.zipcoder;
+
+public interface Animal {
+ String speak();
+}
diff --git a/src/main/java/io/zipcoder/Application.java b/src/main/java/io/zipcoder/Application.java
index 3a257cb..55e18f0 100644
--- a/src/main/java/io/zipcoder/Application.java
+++ b/src/main/java/io/zipcoder/Application.java
@@ -1,5 +1,123 @@
package io.zipcoder;
-public class Application {
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Scanner;
+
+/**
+ * Edited by Frankie
+ */
+
+public class Application implements Comparator {
+ Integer petCount;
+ String petType;
+ String petName;
+ ArrayList pets = new ArrayList();
+ Pet p;
+ Scanner input = new Scanner(System.in);
+ Scanner input1 = new Scanner(System.in);
+ Scanner input2 = new Scanner(System.in);
+
+ public void run() {
+ String welcome = welcomeMessage();
+ System.out.println(welcome + "\nHow many pets do you have?\n");
+ int petCount = input.nextInt();
+ setNumberOfPets(petCount);
+ System.out.println("Now lets get to know them.\n");
+ for (int i = 1; i <= petCount; i++) {
+ System.out.println("Please enter the type of pet #" + i + ": ");
+ String petType = input1.nextLine();
+ System.out.println("Please enter the name of pet #" + i + ": ");
+ String petName = input2.nextLine();
+ addPet(petType, petName);
+ }
+
+ System.out.println("Your pets...\n");
+ System.out.println(listPetsSorted());
+ }
+
+ public String welcomeMessage() {
+ return "Welcome interesting person whom I've never met. Please tell me some things about yourself.";
+ }
+
+ public void setNumberOfPets(int petCount) {
+ this.petCount = petCount;
+ }
+
+ public int getNumberOfPets() {
+ return this.petCount;
+ }
+
+ public void setTypeOfPet(String petType) {
+ this.petType = petType;
+ }
+
+ public String getTypeOfPet() {
+ return this.petType;
+ }
+
+ public void setPetName(String petName) {
+ this.petName = petName;
+ }
+
+ public String getPetName() {
+ return this.petName;
+ }
+
+ public void addPet(String petType, String petName) {
+ if (petType.equals("Dog")) {
+ this.p = new Dog(petName);
+ } else if (petType.equals("Cat")) {
+ this.p = new Cat(petName);
+ } else if (petType.equals("Bird")) {
+ this.p = new Bird(petName);
+ }
+ this.pets.add(p);
+ }
+
+ public boolean getApplication(String petType) {
+ String listMF = listPetsSorted();
+ CharSequence petTy = petType;
+ return listMF.contains(petTy);
+ }
+
+ public String listPetsSorted() {
+ Pet[] temp = pets.toArray(new Pet[pets.size()]);
+ pets.clear();
+ Arrays.sort(temp, sortPets);
+ StringBuilder printOut = new StringBuilder();
+ for (Pet pet : temp) {
+ printOut.append(String.format("%s : %s\n", pet.getType(), pet.getPetName()));
+ }
+ return printOut.toString();
+ }
+
+ public Comparator sortPets = new Comparator() {
+ public int compare(Pet o1, Pet o2) {
+
+ int nameCounter = (o1.getPetName().length() > o2.getPetName().length() ? o1.getPetName().length() : o2.getPetName().length());
+ for (int i = 0; i < nameCounter; i++) {
+ if (o1.getPetName().charAt(i) < o2.getPetName().charAt(i)) {
+ return 1;
+ } else if (o1.getPetName().charAt(i) > o2.getPetName().charAt(i)) {
+ return -1;
+ }
+ }
+ return 0;
+ }
+ };
+
+ public int compare(Pet p1, Pet p2) {
+ int nameCounter = (p1.getPetName().length() > p2.getPetName().length() ? p1.getPetName().length() : p2.getPetName().length());
+ for (int i = 0; i < nameCounter; i++) {
+ if (p1.getPetName().charAt(i) < p2.getPetName().charAt(i)) {
+ return 1;
+ } else if (p1.getPetName().charAt(i) > p2.getPetName().charAt(i)) {
+ return -1;
+ }
+ }
+ return 0;
+ }
}
diff --git a/src/main/java/io/zipcoder/Bird.java b/src/main/java/io/zipcoder/Bird.java
new file mode 100644
index 0000000..aec09db
--- /dev/null
+++ b/src/main/java/io/zipcoder/Bird.java
@@ -0,0 +1,41 @@
+package io.zipcoder;
+
+/**
+ * Edited by Frankie
+ */
+public class Bird extends Pet {
+ String bird;
+ String type;
+
+ public Bird() {
+ this.bird = "";
+ this.type = "Bird";
+ }
+
+ public Bird(String name) {
+ setPetName(name);
+ this.type = "Bird";
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public void setPetName(String word) {
+ this.bird = word;
+ }
+
+ public String getPetName() {
+ return this.bird;
+ }
+
+ public String speak() {
+ Animal dog = new Animal() {
+ public String speak() {
+ return "Squawk";
+ }
+ };
+ return dog.speak();
+ }
+}
diff --git a/src/main/java/io/zipcoder/Cat.java b/src/main/java/io/zipcoder/Cat.java
new file mode 100644
index 0000000..575868b
--- /dev/null
+++ b/src/main/java/io/zipcoder/Cat.java
@@ -0,0 +1,40 @@
+package io.zipcoder;
+/**
+ * Edited by Frankie
+ */
+public class Cat extends Pet {
+ String name;
+ String type;
+
+ public Cat() {
+ this.name = "";
+ this.type = "Cat";
+ }
+
+ public Cat(String name) {
+ setPetName(name);
+ this.type = "Cat";
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public void setPetName(String name) {
+ this.name = name;
+ }
+
+ public String getPetName() {
+ return this.name;
+ }
+
+ public String speak() {
+ Animal dog = new Animal() {
+ public String speak() {
+ return "Meow";
+ }
+ };
+ return dog.speak();
+ }
+}
diff --git a/src/main/java/io/zipcoder/Dog.java b/src/main/java/io/zipcoder/Dog.java
new file mode 100644
index 0000000..542e8ca
--- /dev/null
+++ b/src/main/java/io/zipcoder/Dog.java
@@ -0,0 +1,38 @@
+package io.zipcoder;
+/**
+ * Edited by Frankie
+ */
+public class Dog extends Pet {
+ String name;
+ String type;
+ public Dog(){
+ this.name = "";
+ this.type = "Dog";
+ }
+ public Dog(String name){
+ setPetName(name);
+ this.type = "Dog";
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ public void setPetName(String name){
+ this.name = name;
+ }
+
+ public String getPetName() {
+ return name;
+ }
+
+ public String speak() {
+ Animal dog = new Animal() {
+ public String speak() {
+ return "I just met you and I love you!";
+ }
+ };
+ return dog.speak();
+ }
+}
diff --git a/src/main/java/io/zipcoder/Pet.java b/src/main/java/io/zipcoder/Pet.java
new file mode 100644
index 0000000..c54d186
--- /dev/null
+++ b/src/main/java/io/zipcoder/Pet.java
@@ -0,0 +1,29 @@
+package io.zipcoder;
+/**
+ * Edited by Frankie
+ */
+public abstract class Pet implements Animal {
+ String name;
+ String type;
+
+ public Pet() {
+ this.name = "";
+ this.type = "";
+ }
+
+ public void setPetName(String petName) {
+ this.name = petName;
+ }
+
+ public String getPetName() {
+ return this.name;
+ }
+
+ public void setPetType(String petType) {
+ this.type = petType;
+ }
+
+ public String getType() {
+ return type;
+ }
+}
diff --git a/src/main/java/io/zipcoder/Run.java b/src/main/java/io/zipcoder/Run.java
new file mode 100644
index 0000000..ce220b9
--- /dev/null
+++ b/src/main/java/io/zipcoder/Run.java
@@ -0,0 +1,10 @@
+package io.zipcoder;
+/**
+ * Edited by Frankie
+ */
+public class Run {
+ public static void main(String[] args) {
+ Application application = new Application();
+ application.run();
+ }
+}
diff --git a/src/test/java/io/zipcoder/ApplicationTest.java b/src/test/java/io/zipcoder/ApplicationTest.java
index b744df5..7c734f7 100644
--- a/src/test/java/io/zipcoder/ApplicationTest.java
+++ b/src/test/java/io/zipcoder/ApplicationTest.java
@@ -1,5 +1,66 @@
package io.zipcoder;
+import org.junit.Assert;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * MADE BY APRIL!
+ */
public class ApplicationTest {
+
+ Application application = new Application();
+
+ @Test
+ public void welcomeUserTest() {
+ String message = "Welcome interesting person whom I've never met. Please tell me some things about yourself.";
+ String actual = application.welcomeMessage();
+ Assert.assertEquals(message, actual);
+ }
+
+ @Test
+ public void getNumberOfPetsTest() {
+ int petCount = 2;
+ application.setNumberOfPets(petCount);
+ boolean numberOFPetsHasBeenSet = application.getNumberOfPets() == (petCount);
+ assertTrue(numberOFPetsHasBeenSet);
+ }
+
+ @Test
+ public void getTypeOfPetTest() {
+ String petType = "Dog";
+ application.setTypeOfPet(petType);
+ boolean typeOfPet = application.getTypeOfPet().equals(petType);
+ assertTrue(typeOfPet);
+ }
+
+ @Test
+ public void getPetNameTest() {
+ String petName = "Doug";
+ application.setPetName(petName);
+ boolean nameHasBeenSet = application.getPetName().equals(petName);
+ assertTrue(nameHasBeenSet);
+ }
+
+ @Test
+ public void listPetsSortedTest() {
+ String typeOfPet = "Dog";
+ String petName = "Doug";
+ application.addPet(typeOfPet, petName);
+ String actual = application.listPetsSorted();
+ String expected = "Dog : Doug\n";
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void addPetTest() {
+ String typeOfPet = "Dog";
+ String petName = "Doug";
+ application.addPet(typeOfPet, petName);
+ boolean petHasBeenAdded = application.getApplication(typeOfPet);
+ assertTrue(petHasBeenAdded);
+ }
}
diff --git a/src/test/java/io/zipcoder/BirdTest.java b/src/test/java/io/zipcoder/BirdTest.java
new file mode 100644
index 0000000..ef5af8b
--- /dev/null
+++ b/src/test/java/io/zipcoder/BirdTest.java
@@ -0,0 +1,31 @@
+package io.zipcoder;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+/**
+ * MADE BY APRIL!
+ */
+public class BirdTest {
+ Bird bird;
+
+ @Before
+ public void setUp(){
+ bird = new Bird();
+ }
+ @Test
+ public void setPetNameTest(){
+ String petName = "Kevin";
+ bird.setPetName(petName);
+ boolean nameHasBeenSet = bird.getPetName().contains(petName);
+ assertTrue(nameHasBeenSet);
+ }
+ @Test
+ public void speakTest(){
+ String actual = bird.speak();
+ String expected = "Squawk";
+ assertEquals(expected, actual);
+ }
+}
diff --git a/src/test/java/io/zipcoder/CatTest.java b/src/test/java/io/zipcoder/CatTest.java
new file mode 100644
index 0000000..4d007f9
--- /dev/null
+++ b/src/test/java/io/zipcoder/CatTest.java
@@ -0,0 +1,34 @@
+package io.zipcoder;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+/**
+ * MADE BY APRIL!
+ */
+public class CatTest {
+ Cat cat;
+
+ @Before
+ public void setUp() {
+ cat = new Cat();
+ }
+
+ @Test
+ public void setPetNameTest() {
+ String petName = "Whiskers";
+ cat.setPetName(petName);
+ boolean nameHasBeenSet = cat.getPetName().contains(petName);
+ assertTrue(nameHasBeenSet);
+ }
+
+ @Test
+ public void speakTest() {
+ String actual = cat.speak();
+ String expected = "Meow";
+ assertEquals(expected, actual);
+ }
+}
+
diff --git a/src/test/java/io/zipcoder/DogTest.java b/src/test/java/io/zipcoder/DogTest.java
new file mode 100644
index 0000000..776c37b
--- /dev/null
+++ b/src/test/java/io/zipcoder/DogTest.java
@@ -0,0 +1,31 @@
+package io.zipcoder;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+/**
+ * MADE BY APRIL!
+ */
+public class DogTest {
+ Dog dog;
+
+ @Before
+ public void setUp() {
+ dog = new Dog();
+ }
+ @Test
+ public void setPetNameTest(){
+ String petName = "Doug";
+ dog.setPetName(petName);
+ boolean nameHasBeenSet = dog.getPetName().contains(petName);
+ assertTrue(nameHasBeenSet);
+ }
+ @Test
+ public void speakTest(){
+ String actual = dog.speak();
+ String expected = "I just met you and I love you!";
+ assertEquals(expected, actual);
+ }
+}
diff --git a/src/test/java/io/zipcoder/PetTest.java b/src/test/java/io/zipcoder/PetTest.java
new file mode 100644
index 0000000..3819ad2
--- /dev/null
+++ b/src/test/java/io/zipcoder/PetTest.java
@@ -0,0 +1,26 @@
+package io.zipcoder;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertTrue;
+/**
+ * MADE BY APRIL!
+ */
+public class PetTest {
+ Pet pet;
+
+ @Before
+ public void setUp() {
+ pet = new Dog();
+ }
+
+ @Test
+ public void getPetNameTest() {
+ String petName = "Doug";
+ pet.setPetName(petName);
+ boolean nameHasBeenSet = pet.getPetName().contains(petName);
+ assertTrue(nameHasBeenSet);
+ }
+}
+