diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..9a874b5 Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..7b0d367 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000..55c1fcb Binary files /dev/null and b/src/main/.DS_Store differ diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store new file mode 100644 index 0000000..b7618de Binary files /dev/null and b/src/main/java/.DS_Store differ diff --git a/src/main/java/io/.DS_Store b/src/main/java/io/.DS_Store new file mode 100644 index 0000000..552b8ff Binary files /dev/null and b/src/main/java/io/.DS_Store differ diff --git a/src/main/java/io/zipcoder/Application.java b/src/main/java/io/zipcoder/Application.java index 3a257cb..d324889 100644 --- a/src/main/java/io/zipcoder/Application.java +++ b/src/main/java/io/zipcoder/Application.java @@ -1,5 +1,83 @@ package io.zipcoder; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; public class Application { + private ArrayList pets = new ArrayList<>(); + private Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { + Application application = new Application(); + application.start(); + } + + + public void start() { + System.out.println("How many pets do you have?"); + String numberOfPetsString = scanner.nextLine(); + int numberOfPets = Integer.parseInt(numberOfPetsString); + + for(int i=0;i { + + public int compare(Pet pet1, Pet pet2) { + Integer result = null; + + String pet1Name = pet1.getName(); + String pet2Name = pet2.getName(); + + int nameComparison = pet1Name.compareTo(pet2Name); + result = nameComparison; + + boolean sameName = (nameComparison == 0); + + if (sameName) { + Class pet1Class = pet1.getClass(); + Class pet2Class = pet2.getClass(); + + String pet1ClassSimpleName = pet1Class.getSimpleName(); + String pet2ClassSimpleName = pet2Class.getSimpleName(); + + int classComparison = pet1ClassSimpleName.compareTo(pet2ClassSimpleName); + result = classComparison; + } + + return result; + } +} \ No newline at end of file diff --git a/src/main/java/io/zipcoder/Dog.java b/src/main/java/io/zipcoder/Dog.java new file mode 100644 index 0000000..9fc0ff1 --- /dev/null +++ b/src/main/java/io/zipcoder/Dog.java @@ -0,0 +1,26 @@ +package io.zipcoder; + +public class Dog extends Pet { + + + public Dog() { + + } + + public Dog(String name) { + super(name); + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + + public String speak() { + return "I'm such a wimp! I'm running from a cat!"; + } +} diff --git a/src/main/java/io/zipcoder/Pet.java b/src/main/java/io/zipcoder/Pet.java new file mode 100644 index 0000000..6937d6a --- /dev/null +++ b/src/main/java/io/zipcoder/Pet.java @@ -0,0 +1,28 @@ +package io.zipcoder; + +import java.lang.Comparable; + +public abstract class Pet { + + protected String name; + + //Constructors + protected Pet(){} + + protected Pet(String name) + { + this.name = name; + } + + + public void setName(String name) { + + } + + public String getName() { + + return this.name; + } + + public abstract String speak(); +} diff --git a/src/main/java/io/zipcoder/Snake.java b/src/main/java/io/zipcoder/Snake.java new file mode 100644 index 0000000..45dcbe0 --- /dev/null +++ b/src/main/java/io/zipcoder/Snake.java @@ -0,0 +1,26 @@ +package io.zipcoder; + +public class Snake extends Pet { + + + public Snake() { + } + + public Snake(String name) { + super(name); + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String speak() { + return "I have seen all the dead seasons, and the great trees and the old elephants, and the rocks that were " + + "bare and sharp-pointed ere the moss grew. Art thou still alive, Manling?"; + } +} diff --git a/src/test/java/io/zipcoder/ApplicationTest.java b/src/test/java/io/zipcoder/ApplicationTest.java index b744df5..3ff86cb 100644 --- a/src/test/java/io/zipcoder/ApplicationTest.java +++ b/src/test/java/io/zipcoder/ApplicationTest.java @@ -1,5 +1,65 @@ package io.zipcoder; +import org.junit.Test; +import org.junit.Assert; public class ApplicationTest { + + @Test + public void testAddPets() { + //Given + Application application = new Application(); + Pet pet1 = new Cat(); + + //When + application.add(pet1); + Pet[] petArray = application.getPets(); + + + //Then + Pet firstPet = petArray[0]; + Assert.assertEquals(pet1, firstPet); + } + + @Test + public void testGetPets() { + // Given + Application application = new Application(); + Pet pet1 = new Dog(); + Pet pet2 = new Cat(); + Pet pet3 = new Snake(); + Pet[] expectedPets = new Pet[]{pet1, pet2, pet3}; + + application.add(pet1); + application.add(pet2); + application.add(pet3); + + // When + Pet[] actualPets = application.getPets(); + + // Then + Assert.assertEquals(expectedPets, actualPets); + } + + + @Test + public void testCreatePet() { + //Given + Application application = new Application(); + String petType = "Dog"; + String petName = "Milo"; + + // When + Pet pet = application.createPet(petType, petName); + + //Then + Assert.assertTrue(pet instanceof Dog); + } + + @Test + public void testSomething2() { + + } + + } diff --git a/src/test/java/io/zipcoder/BirdTest.java b/src/test/java/io/zipcoder/BirdTest.java new file mode 100644 index 0000000..e212a1d --- /dev/null +++ b/src/test/java/io/zipcoder/BirdTest.java @@ -0,0 +1,42 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + +public class BirdTest { + + @Test + public void testBirdConstructor() + { + Bird bird = new Bird("Jacob"); + + String actual = bird.getName(); + + String expected = "Jacob"; + + Assert.assertEquals(expected, actual); + + + } + + + @Test + public void testSpeakBird() + { + Bird bird = new Bird(); + String actual = bird.speak(); + String expected = "chirp"; + Assert.assertEquals(expected,actual); + + } + + @Test + public void testSetBirdName() + { + Bird bird = new Bird(); + bird.setName("Robin"); + String expected = "Robin"; + String actual = bird.getName(); + Assert.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..cbf96d0 --- /dev/null +++ b/src/test/java/io/zipcoder/CatTest.java @@ -0,0 +1,40 @@ +package io.zipcoder; + +import org.junit.Test; +import org.junit.Assert; + +public class CatTest { + + @Test + public void testSpeakCat() { + Cat cat = new Cat(); + String actual = cat.speak(); + String expected = "meow"; + } + + public void getNamesOfCats() { + Cat cat = new Cat("Tom"); + String expected = "Tom"; + String actual = cat.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetCatName() + { + Cat cat = new Cat(); + + cat.setName("Felix"); + String expected = "Felix"; + String actual = cat.getName(); + + Assert.assertEquals(expected, actual); + } + + public void catSpeakTest() { + Cat cat = new Cat("Tom"); + String expected = "Hang in there."; + String actual = cat.speak(); + Assert.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..b14995b --- /dev/null +++ b/src/test/java/io/zipcoder/DogTest.java @@ -0,0 +1,39 @@ +package io.zipcoder; + +import org.junit.Test; +import org.junit.Assert; + +public class DogTest { + + @Test + public void testSpeakDog() { + Dog dog = new Dog(); + String actual = dog.speak(); + String expected = "woof"; + } + + @Test + public void getNamesOfDog() { + Dog dog = new Dog("Chance"); + String expected = "Chance"; + String actual = dog.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void testSetDogName() { + Dog dog = new Dog(); + + dog.setName("Spot"); + String expected = "Spot"; + String actual = dog.getName(); + } + + @Test + public void dogSpeakTest() { + Dog dog = new Dog("Chance"); + String expected = "I'm such a wimp! I'm running from a cat!"; + String actual = dog.speak(); + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/PetsTest.java b/src/test/java/io/zipcoder/PetsTest.java new file mode 100644 index 0000000..d6e247c --- /dev/null +++ b/src/test/java/io/zipcoder/PetsTest.java @@ -0,0 +1,16 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + +public class PetsTest { + + @Test + public void getName() { + String expected = "Spot"; + Pet pet = new Dog("Spot"); + pet.setName(expected); + String actual = pet.getName(); + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/SnakeTest.java b/src/test/java/io/zipcoder/SnakeTest.java new file mode 100644 index 0000000..defcbbf --- /dev/null +++ b/src/test/java/io/zipcoder/SnakeTest.java @@ -0,0 +1,28 @@ +package io.zipcoder; + +import org.junit.Assert; +import org.junit.Test; + +public class SnakeTest { + + @Test + public void getNamesOfSnake() { + Snake snake = new Snake("Kaa"); + String expected = "Kaa"; + String actual = snake.getName(); + Assert.assertEquals(expected, actual); + } + + @Test + public void snakeSpeakTest() { + Snake snake = new Snake("Kaa"); + String expected = "I have seen all the dead seasons, and the great trees and the old elephants, " + + "and the rocks that were bare and sharp-pointed ere the moss grew. Art thou still alive, Manling?"; + String actual = snake.speak(); + Assert.assertEquals(expected, actual); + } +/* + @Test + public void ge + */ +}