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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>io.zipcoder</groupId>
<artifactId>Interfaces</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/io/zipcoder/Application.java

This file was deleted.

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

public class Cat extends Pets {

public Cat(String name) {
super(name, "cat");
}

public String speak() {
return "Mow mow...";
}
}
11 changes: 11 additions & 0 deletions src/main/java/io/zipcoder/pets/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.zipcoder.pets;

public class Dog extends Pets {

public Dog(String name){
super(name, "dog");
}
public String speak() {
return "Wooooooof!";
}
}
12 changes: 12 additions & 0 deletions src/main/java/io/zipcoder/pets/Fish.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.zipcoder.pets;

public class Fish extends Pets{

public Fish(String name){
super(name,"fish");
}

public String speak() {
return "Glub glub...";
}
}
34 changes: 34 additions & 0 deletions src/main/java/io/zipcoder/pets/Pets.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.zipcoder.pets;

public abstract class Pets {
private String name;
private String type;


public Pets(String name, String type){
this.name = name;
this.type = type;
}

public String name(){
return name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getType() { return type; }

public void setType(String type) { this.type = type; }

abstract public String speak();



}

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

import io.zipcoder.Console;
import io.zipcoder.pets.Pets;

import java.util.ArrayList;
import java.util.Collections;

/**
* Created by leon on 11/6/17.
*/
public class Application {
public static void main(String[] args) {
petApp();
}
public static void petApp() {
Integer numofPets = getNumOfPets();
Console.println("TELL ME MORE... \n", numofPets);

String[] petTypes = new String[numofPets];
String[] petNames = new String[numofPets];
for(int i = 0; i < numofPets; i++){
petNames[i] = Console.getStringInput(String.format("Tell me the name of pet %s ...\n", i+1));
petTypes[i] = Console.getStringInput(String.format("Ooh... what KIND of pet is %s ... \n", petNames[i]));
}
PetLodge cozy = new PetLodge(numofPets, petNames, petTypes);
cozy.displayPetInfo();
}

protected static Integer getNumOfPets() {
return Console.getIntegerInput("I'm Kai! I have a cat named Boots. How many pets do you have?\n");
}


}
29 changes: 29 additions & 0 deletions src/main/java/io/zipcoder/utils/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.zipcoder;

import java.util.Scanner;

public class Console {

public static void print(String output, Object... args) {
System.out.printf(output, args);
}

public static void println(String output, Object... args) {
print(output + "\n", args);
}

public static String getStringInput(String prompt) {
Scanner scanner = new Scanner(System.in);
print(prompt);
String userInput = scanner.nextLine();
return userInput;
}

public static Integer getIntegerInput(String prompt) {
Scanner scanner = new Scanner(System.in);
print(prompt);
Integer userInput = Integer.valueOf(scanner.nextLine());
return userInput;
}
}

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

import io.zipcoder.Console;
import io.zipcoder.pets.Cat;
import io.zipcoder.pets.Dog;
import io.zipcoder.pets.Fish;
import io.zipcoder.pets.Pets;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;

public class PetLodge {

public PetLodge() {}
private Pets[] pets;
private static ArrayList<Pets> listOPets = new ArrayList<Pets>();

public PetLodge(Integer numOfPets, String[] petNames, String[] petTypes){
this.pets = createPets(numOfPets, petNames, petTypes);
}

public Pets[] createPets(Integer numOfPets, String[] petNames, String[] petTypes){
Pets[] pets = new Pets[numOfPets];
for(int i = 0; i < numOfPets; i++){
pets[i] = createPetFromType(petNames[i], petTypes[i]);
}
return pets;
}

public Pets createPetFromType(String petName, String petType) {
Pets pet;
if (petType.equals("dog")) {
pet = new Dog(petName);
}
else if (petType.equals("cat")) {
pet = new Cat(petName);
}
else if (petType.equals("fish")) {
pet = new Fish(petName);
}
else{
pet = new Fish(petName);
}
return pet;
}

public void displayPetInfo(){
Console.println("You got %s pets!", pets.length);

for(int i = 0; i< pets.length; i++){
Console.println("Pet %s is a %s named %s! %s", i+1, pets[i].getType(), pets[i].getName(), pets[i].speak());

}
sortTypeBeforeName(listOPets);
}
public static ArrayList sortTypeBeforeName(ArrayList<Pets> pets) {
Collections.sort(pets, new PetTypeSorting());
Collections.sort(pets, new PetNameSorting());
return pets;
}
public Pets[] getPets() {
return this.pets;
}

}
11 changes: 11 additions & 0 deletions src/main/java/io/zipcoder/utils/PetNameSorting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.zipcoder.utils;

import io.zipcoder.pets.Pets;

import java.util.Comparator;

public class PetNameSorting implements Comparator<Pets> {
public int compare(Pets p1, Pets p2) {
return p1.getName().compareTo(p2.getName());
}
}
12 changes: 12 additions & 0 deletions src/main/java/io/zipcoder/utils/PetTypeSorting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.zipcoder.utils;

import io.zipcoder.pets.Pets;

import java.util.Comparator;

public class PetTypeSorting implements Comparator<Pets> {

public int compare(Pets p1, Pets p2) {
return p1.getType().compareTo(p2.getType());
}
}
42 changes: 42 additions & 0 deletions src/test/java/io/zipcoder/pets/CatTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.zipcoder.pets;

import org.junit.Assert;
import org.junit.Test;

public class CatTest {
@Test
public void speak1() {
Cat cat = new Cat("Yelp");
String actual = cat.speak();
String expected = "Mow mow...";
Assert.assertEquals(expected, actual);
}

@Test
public void speak2() {
Cat cat = new Cat("Paul");
String actual = cat.speak();
String expected = "Mow mow...";
Assert.assertEquals(expected, actual);
}

@Test
public void speak3() {
Cat cat = new Cat("Opal");
String actual = cat.speak();
String expected = "Mow mow...";
Assert.assertEquals(expected, actual);
}

@Test
public void dogNameConstructorTest() {
Cat cat = new Cat("Ovard");
Assert.assertEquals("Ovard", cat.getName());
}
@Test
public void dogTypeConstructorTest() {
Cat cat = new Cat("Pumpkin");
Assert.assertEquals("cat", cat.getType());
}

}
42 changes: 42 additions & 0 deletions src/test/java/io/zipcoder/pets/DogTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.zipcoder.pets;

import org.junit.Assert;
import org.junit.Test;

public class DogTest {
@Test
public void speak1() {
Dog doge = new Dog("Bobert");
String actual = doge.speak();
String expected = "Wooooooof!";
Assert.assertEquals(expected, actual);
}

@Test
public void speak2() {
Dog doge = new Dog("Harold");
String actual = doge.speak();
String expected = "Wooooooof!";
Assert.assertEquals(expected, actual);
}

@Test
public void speak3() {
Dog doge = new Dog("Mary");
String actual = doge.speak();
String expected = "Wooooooof!";
Assert.assertEquals(expected, actual);
}

@Test
public void dogNameConstructorTest() {
Dog doge = new Dog("Bob");
Assert.assertEquals("Bob", doge.getName());
}
@Test
public void dogTypeConstructorTest() {
Dog doge = new Dog("Bob");
Assert.assertEquals("dog", doge.getType());
}

}
43 changes: 43 additions & 0 deletions src/test/java/io/zipcoder/pets/FishTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.zipcoder.pets;

import org.junit.Assert;
import org.junit.Test;


public class FishTest {
@Test
public void speak1() {
Fish fsh = new Fish("Yellow");
String actual = fsh.speak();
String expected = "Glub glub...";
Assert.assertEquals(expected, actual);
}

@Test
public void speak2() {
Fish fsh = new Fish("Pail");
String actual = fsh.speak();
String expected = "Glub glub...";
Assert.assertEquals(expected, actual);
}

@Test
public void speak3() {
Fish fsh = new Fish("Martin");
String actual = fsh.speak();
String expected = "Glub glub...";
Assert.assertEquals(expected, actual);
}

@Test
public void dogNameConstructorTest() {
Fish doge = new Fish("Bob");
Assert.assertEquals("Bob", doge.getName());
}
@Test
public void dogTypeConstructorTest() {
Fish doge = new Fish("Eagle");
Assert.assertEquals("fish", doge.getType());
}

}
Loading