Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/main/java/io/zipcoder/Application.java

This file was deleted.

27 changes: 27 additions & 0 deletions src/main/java/io/zipcoder/pets/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.zipcoder.pets;


import java.util.ArrayList;
import java.util.Scanner;

public class Application {

private final ArrayList<Pet> petArrayList;

public Application(){
this.petArrayList = new ArrayList<Pet>();
}

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);
}

}
29 changes: 29 additions & 0 deletions src/main/java/io/zipcoder/pets/Bunny.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
30 changes: 30 additions & 0 deletions src/main/java/io/zipcoder/pets/Cat.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions src/main/java/io/zipcoder/pets/Dog.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
41 changes: 41 additions & 0 deletions src/main/java/io/zipcoder/pets/Pet.java
Original file line number Diff line number Diff line change
@@ -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;
}



}
17 changes: 17 additions & 0 deletions src/main/java/io/zipcoder/pets/PetCompare.java
Original file line number Diff line number Diff line change
@@ -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<Pet>{

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;
}
}
5 changes: 0 additions & 5 deletions src/test/java/io/zipcoder/ApplicationTest.java

This file was deleted.

46 changes: 46 additions & 0 deletions src/test/java/io/zipcoder/pets/BunnyTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
46 changes: 46 additions & 0 deletions src/test/java/io/zipcoder/pets/CatTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
47 changes: 47 additions & 0 deletions src/test/java/io/zipcoder/pets/DogTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
26 changes: 26 additions & 0 deletions src/test/java/io/zipcoder/pets/PetCompareTest.java
Original file line number Diff line number Diff line change
@@ -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<Pet> petTest = new ArrayList<Pet>();
//
// Cat cat1 = new Cat("Annie", "Meow", "Cat");
// Dog dog2 = new Dog("Cookie", "Woof", "Dog");
// Dog dog1 = new Dog("Bob", "Bark", "Dog");
//
// }
//}
Loading