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/Application.java b/src/main/java/io/zipcoder/pets/Application.java new file mode 100644 index 0000000..bede3fa --- /dev/null +++ b/src/main/java/io/zipcoder/pets/Application.java @@ -0,0 +1,27 @@ +package io.zipcoder.pets; + + +import java.util.ArrayList; +import java.util.Scanner; + +public class Application { + + private final ArrayList petArrayList; + + public Application(){ + this.petArrayList = new ArrayList(); + } + + public static void main (String args[]){ + Scanner sc = new Scanner(System.in); + System.out.println("How many pets do you have? "); + String quantity = sc.nextLine(); + System.out.println("What kind of pets do you have?"); + String type = sc.nextLine(); + System.out.println("What are your pets' names?"); + String names = sc.nextLine(); + + System.out.println("Number of Pets: " + quantity + "\n" + "Kind of pets: " + type + "\n" + "Pets names: " + names); + } + +} diff --git a/src/main/java/io/zipcoder/pets/Bunny.java b/src/main/java/io/zipcoder/pets/Bunny.java new file mode 100644 index 0000000..8fb295d --- /dev/null +++ b/src/main/java/io/zipcoder/pets/Bunny.java @@ -0,0 +1,29 @@ +package io.zipcoder.pets; + +public class Bunny extends Pet { + + private String name; + private String speak; + + public Bunny(String name, String type, String speak) { + super(name, type, speak); + this.name = name; + this.speak = speak; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + @Override + public String getSpeak() { + return speak; + } + @Override + public void setSpeak(String speak) { + this.speak = speak; + } +} 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..197d6be --- /dev/null +++ b/src/main/java/io/zipcoder/pets/Cat.java @@ -0,0 +1,30 @@ +package io.zipcoder.pets; + +public class Cat extends Pet{ + + private String name; + private String speak; + private String type; + + public Cat(String name, String speak, String type) { + super(name, speak, type); + this.name = name; + this.speak = speak; + this.type = type; + } + public String getName() { + return super.getName(); + } + + public void setName(String name) { + this.name = name; + } + @Override + public String getSpeak() { + return speak; + } + @Override + public void setSpeak(String speak) { + this.speak = speak; + } +} 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..9746e33 --- /dev/null +++ b/src/main/java/io/zipcoder/pets/Dog.java @@ -0,0 +1,32 @@ +package io.zipcoder.pets; + +public class Dog extends Pet { + + private String name; + private String speak; + private String type; + + public Dog(String name, String speak, String type) { + super(name, speak, type); + this.name = name; + this.speak = speak; + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + @Override + public String getSpeak() { + return speak; + } + @Override + public void setSpeak(String speak){ + this.speak = speak; + } + +} diff --git a/src/main/java/io/zipcoder/pets/Pet.java b/src/main/java/io/zipcoder/pets/Pet.java new file mode 100644 index 0000000..f8de999 --- /dev/null +++ b/src/main/java/io/zipcoder/pets/Pet.java @@ -0,0 +1,41 @@ +package io.zipcoder.pets; + +public class Pet { + + private String name; + private String type; + private String speak; + + public Pet(String name, String type, String speak) { + this.name = name; + this.speak = speak; + this.type = type; + } + + public void setType(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public String getSpeak() { + return speak; + } + + public void setSpeak(String speak) { + this.speak = speak; + } + + + +} diff --git a/src/main/java/io/zipcoder/pets/PetCompare.java b/src/main/java/io/zipcoder/pets/PetCompare.java new file mode 100644 index 0000000..9d3c9f8 --- /dev/null +++ b/src/main/java/io/zipcoder/pets/PetCompare.java @@ -0,0 +1,17 @@ +package io.zipcoder.pets; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +public class PetCompare implements Comparator{ + + public int compare(Pet pet1, Pet pet2) { + int compareName = pet1.getClass().getSimpleName().compareTo(pet2.getClass().getSimpleName()); + if (compareName == 0) { + return pet1.getName().compareTo(pet2.getName()); + } + return compareName; + } + } diff --git a/src/test/java/io/zipcoder/ApplicationTest.java b/src/test/java/io/zipcoder/ApplicationTest.java deleted file mode 100644 index b744df5..0000000 --- a/src/test/java/io/zipcoder/ApplicationTest.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.zipcoder; - - -public class ApplicationTest { -} diff --git a/src/test/java/io/zipcoder/pets/BunnyTest.java b/src/test/java/io/zipcoder/pets/BunnyTest.java new file mode 100644 index 0000000..c7db505 --- /dev/null +++ b/src/test/java/io/zipcoder/pets/BunnyTest.java @@ -0,0 +1,46 @@ +package io.zipcoder.pets; + +import org.junit.Assert; +import org.junit.Test; + +public class BunnyTest { + @Test + public void testInheritance() { + Bunny bunny = new Bunny("Mr. Fluffles", "Bunny", "Sniff"); + Assert.assertTrue(bunny instanceof Pet); + } + + + @Test + public void testGetName() { + Bunny bunny = new Bunny("Mr. Fluffles", "Bunny", "Sniff"); + String expectedName = "Mr. Fluffles"; + String actualName = bunny.getName(); + Assert.assertEquals(expectedName, actualName); + + } + @Test + public void testSetName() { + Bunny bunny = new Bunny("Mr. Fluffles", "Bunny", "Sniff"); + String expectedName = "Mr. Fluffles"; + bunny.setName("Mr. Fluffles"); + String actualName = bunny.getName(); + Assert.assertEquals(expectedName, actualName); + + } + @Test + public void testSetSpeak(){ + Bunny bunny = new Bunny("Mr. Fluffles", "Bunny", "Sniff"); + String expected = "Sniff"; + bunny.setSpeak("Sniff"); + String actual = bunny.getSpeak(); + Assert.assertEquals(expected, actual); + } + @Test + public void testGetSpeak(){ + Bunny bunny = new Bunny("Mr. Fluffles", "Bunny", "Sniff"); + String expected = "Sniff"; + String actual = bunny.getSpeak(); + Assert.assertEquals(expected, actual); + } +} 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..7cdaf5f --- /dev/null +++ b/src/test/java/io/zipcoder/pets/CatTest.java @@ -0,0 +1,46 @@ +package io.zipcoder.pets; + +import org.junit.Assert; +import org.junit.Test; + +public class CatTest { + @Test + public void testInheritance() { + Cat cat = new Cat("Baby", "Meow", "Cat"); + Assert.assertTrue(cat instanceof Pet); + } + + + @Test + public void testGetName() { + Cat cat = new Cat("Baby", "Meow", "Cat"); + String expectedName = "Baby"; + String actualName = cat.getName(); + Assert.assertEquals(expectedName, actualName); + + } + @Test + public void testSetName() { + Cat cat = new Cat("Baby", "Meow", "Cat"); + String expectedName = "Baby"; + cat.setName("Baby"); + String actualName = cat.getName(); + Assert.assertEquals(expectedName, actualName); + + } + @Test + public void testSetSpeak(){ + Cat cat = new Cat("Baby", "Meow", "Cat"); + String expected = "Meow"; + cat.setSpeak("Meow"); + String actual = cat.getSpeak(); + Assert.assertEquals(expected, actual); + } + @Test + public void testGetSpeak(){ + Cat cat = new Cat("Baby", "Meow", "Cat"); + String expected = "Meow"; + String actual = cat.getSpeak(); + Assert.assertEquals(expected, actual); + } +} 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..6be8400 --- /dev/null +++ b/src/test/java/io/zipcoder/pets/DogTest.java @@ -0,0 +1,47 @@ +package io.zipcoder.pets; + +import org.junit.Assert; +import org.junit.Test; + +public class DogTest { + + @Test + public void testInheritance() { + Dog dog = new Dog("Cookie", "Woof", "Dog"); + Assert.assertTrue(dog instanceof Pet); + } + + + @Test + public void testGetName() { + Dog dog = new Dog("Cookie", "Woof", "Dog"); + String expectedName = "Cookie"; + String actualName = dog.getName(); + Assert.assertEquals(expectedName, actualName); + } + + @Test + public void testSetName(){ + Dog dog = new Dog("Cookie", "Woof", "Dog"); + String expected = "Cookie"; + dog.setName("Cookie"); + String actual = dog.getName(); + Assert.assertEquals(expected, actual); + + } + @Test + public void testGetSpeak(){ + Dog dog = new Dog("Cookie", "Woof", "Dog"); + String expected = "Woof"; + String actual = dog.getSpeak(); + Assert.assertEquals(expected, actual); + } + @Test + public void testSetSpeak(){ + Dog dog = new Dog("Cookie", "Woof", "Dog"); + String expected = "Woof"; + dog.setSpeak("Woof"); + String actual = dog.getSpeak(); + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/io/zipcoder/pets/PetCompareTest.java b/src/test/java/io/zipcoder/pets/PetCompareTest.java new file mode 100644 index 0000000..6ce59db --- /dev/null +++ b/src/test/java/io/zipcoder/pets/PetCompareTest.java @@ -0,0 +1,26 @@ +package io.zipcoder.pets; +import org.junit.Assert; +import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +//public class PetCompareTest { +// +// public PetCompareTest() { +// +// } +// +// @Test +// //Application test = new Application(); +// PetCompare petCompare = new PetCompare(); +// +// ArrayList petTest = new ArrayList(); +// +// Cat cat1 = new Cat("Annie", "Meow", "Cat"); +// Dog dog2 = new Dog("Cookie", "Woof", "Dog"); +// Dog dog1 = new Dog("Bob", "Bark", "Dog"); +// +// } +//} diff --git a/src/test/java/io/zipcoder/pets/PetTest.java b/src/test/java/io/zipcoder/pets/PetTest.java new file mode 100644 index 0000000..e924ed4 --- /dev/null +++ b/src/test/java/io/zipcoder/pets/PetTest.java @@ -0,0 +1,54 @@ +package io.zipcoder.pets; +import org.junit.Assert; +import org.junit.Test; + +public class PetTest { + + @Test + public void testConstructor(){ + Pet pet = new Pet("Tina", "Llama", "Fat"); + String expected = "Tina"; + String actual = pet.getName(); + Assert.assertEquals(expected, actual); + } + @Test + public void testSetName(){ + Pet pet = new Pet("Tina", "Llama", "Fat"); + String expected = "Tina"; + pet.setName(expected); + String actual = pet.getName(); + Assert.assertEquals(expected, actual); + } + @Test + public void testGetType(){ + Pet pet = new Pet("Tina", "Llama", "Fat"); + String expected = "Llama"; + String actual = pet.getType(); + Assert.assertEquals(expected, actual); + } + @Test + public void testSetType(){ + Pet pet = new Pet("Tina", "Llama", "Fat"); + String expected = "Llama"; + pet.setType(expected); + String actual = pet.getType(); + Assert.assertEquals(expected, actual); + } + @Test + public void testGetSpeak(){ + Pet pet = new Pet("Tina", "Llama", "Fat"); + String expected = "Fat"; + pet.setType(expected); + String actual = pet.getSpeak(); + Assert.assertEquals(expected, actual); + } + @Test + public void testSetSpeak(){ + Pet pet = new Pet("Tina", "Llama", "Fat"); + String expected = "Fat"; + pet.setType(expected); + String actual = pet.getSpeak(); + Assert.assertEquals(expected, actual); + } + +}