diff --git a/src/main/java/io/zipcoder/Application.java b/src/main/java/io/zipcoder/Application.java index 3a257cb..cf6b76c 100644 --- a/src/main/java/io/zipcoder/Application.java +++ b/src/main/java/io/zipcoder/Application.java @@ -1,5 +1,76 @@ package io.zipcoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Scanner; public class Application { + + + private int numberOfPets = 0; + private ArrayList typeOfPet = new ArrayList(); + private ArrayList nameOfPet = new ArrayList(); + private ArrayList allPets = new ArrayList(); + + private HashMap allPetCollection = new HashMap(); + + Scanner userInput = new Scanner(System.in); + + + public void getPetInfo() { + System.out.println("Hey fool! How many pets do you have?"); + numberOfPets = userInput.nextInt(); + userInput.nextLine(); + + if (numberOfPets > 0) { + for (int i = 0; i < numberOfPets; i++) { + String name; + String type; + System.out.println("What type of pet is pet #: " + (i +1) + "?\n Only enter Dog, Cat or Snake"); + type = userInput.nextLine(); + System.out.println("What is your " + type + "'s name?"); + name = userInput.nextLine(); + + this.allPets.add(PetFactory.createPet(type,name)); + } + } else getPetInfo(); + + } + + public void buildPetMap (ArrayList typeOfPet, ArrayList name) { + for (int i = 0; i < typeOfPet.size(); i++) { + allPetCollection.put(typeOfPet.get(i), nameOfPet.get(i)); + } + } + + public String getPetFromMap(String key){ + return this.allPetCollection.get(key); + } + + + public void setNumberOfPets() { + this.numberOfPets =numberOfPets; + } + + public Integer getNumberOfPets() { + return this.numberOfPets; + } + + public void allPetsSpeak() { + for (Pets pet : allPets) { + System.out.println("Your " + pet.getClass().getSimpleName() + " named " + pet.getName() + " says " + pet.speak() +"!"); + } + } + + + public static void main(String[] args) { + + Application app = new Application(); + app.getPetInfo(); + app.allPetsSpeak(); + } + + + + } diff --git a/src/main/java/io/zipcoder/Cat.java b/src/main/java/io/zipcoder/Cat.java new file mode 100644 index 0000000..ad276b2 --- /dev/null +++ b/src/main/java/io/zipcoder/Cat.java @@ -0,0 +1,17 @@ +package io.zipcoder; + +public class Cat extends Pets { + + public Cat(String name) { + super(name); + + } + + + @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..86d4802 --- /dev/null +++ b/src/main/java/io/zipcoder/Dog.java @@ -0,0 +1,23 @@ +package io.zipcoder; + +public class Dog extends Pets { + + + + + public Dog (String name) { + super(name); + + + } + + + + + + @Override + public String speak() { + return "bark"; + } + +} diff --git a/src/main/java/io/zipcoder/PetFactory.java b/src/main/java/io/zipcoder/PetFactory.java new file mode 100644 index 0000000..bcb4be3 --- /dev/null +++ b/src/main/java/io/zipcoder/PetFactory.java @@ -0,0 +1,17 @@ +package io.zipcoder; + +public class PetFactory { + + public static Pets createPet(String type, String name) { + + if (type.equalsIgnoreCase("Dog")) + return new Dog(name); + else if (type.equalsIgnoreCase("Cat")) + return new Cat(name); + else if (type.equalsIgnoreCase("Snake")) + return new Snake(name); + + return null; + } +} + diff --git a/src/main/java/io/zipcoder/Pets.java b/src/main/java/io/zipcoder/Pets.java new file mode 100644 index 0000000..4c0e1dc --- /dev/null +++ b/src/main/java/io/zipcoder/Pets.java @@ -0,0 +1,48 @@ +package io.zipcoder; + +import java.util.Comparator; + +public abstract class Pets implements Comparable, Comparator { + + public String name; + + + public Pets(String name) { + this.name = name; + + } + + + public abstract String speak(); + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int compareTo(Pets pet) { + int compare = this.getName().compareToIgnoreCase(pet.getName()); + + if (compare != 0) { + return compare; + } else { + compare = this.getClass().getSimpleName().compareToIgnoreCase(pet.getClass().getSimpleName()); + return compare; + } + } + + public int compare(Pets pet1, Pets pet2) { + int compare = pet1.getClass().getSimpleName().compareToIgnoreCase(pet2.getClass().getSimpleName()); + if (compare != 0) { + return compare; + } else { + compare = pet1.getName().compareToIgnoreCase(pet2.getName()); + return compare; + + } + } +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/Snake.java b/src/main/java/io/zipcoder/Snake.java new file mode 100644 index 0000000..cd8d011 --- /dev/null +++ b/src/main/java/io/zipcoder/Snake.java @@ -0,0 +1,16 @@ +package io.zipcoder; + +public class Snake extends Pets { + + public Snake (String name) { + super(name); + } + + @Override + public String speak() { + + return "hiss"; + } + + +} diff --git a/src/test/java/io/zipcoder/CatTest.java b/src/test/java/io/zipcoder/CatTest.java new file mode 100644 index 0000000..78af56e --- /dev/null +++ b/src/test/java/io/zipcoder/CatTest.java @@ -0,0 +1,32 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class CatTest { + + @Test + public void getNameOfCatsTest() { + + Cat cat = new Cat("Felix"); + + String expected = "Felix"; + String actual = cat.getName(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void catSpeakTest() { + Cat cat = new Cat("Felix"); + String expected = "meow"; + String actual = cat.speak(); + + 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..0ef2e23 --- /dev/null +++ b/src/test/java/io/zipcoder/DogTest.java @@ -0,0 +1,31 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class DogTest { + + @Test + public void getNameOfDogsTest() { + + Dog dog = new Dog("Butch"); + + String expected = "Butch"; + String actual = dog.getName(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void dogSpeakTest() { + Dog dog = new Dog(""); + String expected = "bark"; + String actual = dog.speak(); + + Assert.assertEquals(expected, actual); + + } + } \ No newline at end of file diff --git a/src/test/java/io/zipcoder/PetsTest.java b/src/test/java/io/zipcoder/PetsTest.java new file mode 100644 index 0000000..ab22d8a --- /dev/null +++ b/src/test/java/io/zipcoder/PetsTest.java @@ -0,0 +1,22 @@ +package io.zipcoder; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PetsTest { + + @Test + public void getPetNameTest() { + + + } + + + @Test + public void speakTest() { + + } + + +} \ No newline at end of file diff --git a/src/test/java/io/zipcoder/SnakeTest.java b/src/test/java/io/zipcoder/SnakeTest.java new file mode 100644 index 0000000..f7e701a --- /dev/null +++ b/src/test/java/io/zipcoder/SnakeTest.java @@ -0,0 +1,40 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SnakeTest { + + @Before + public void setUp() { + } + + + @Test + public void getNameOfSnakesTest() { + + Snake snake = new Snake("Luke"); + + String expected = "Luke"; + String actual = snake.getName(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void snakeSpeakTest() { + Snake snake = new Snake("Luke"); + String expected = "hiss"; + String actual = snake.speak(); + + Assert.assertEquals(expected, actual); + + + } + + +} \ No newline at end of file