diff --git a/src/main/java/Doggo.java b/src/main/java/Doggo.java new file mode 100644 index 0000000..af7f24a --- /dev/null +++ b/src/main/java/Doggo.java @@ -0,0 +1,67 @@ +/* Class representing a Doggo. + */ + +public class Doggo implements Tradable, Domesticatable{ + private int price; + private int happiness; + + public Doggo() { + this.price = 5; + this.happiness = 10; + } + + /** + * Returns the sound the Doggo makes. + * + * @return A String representing the Doggo's sound. + */ + @Override + public String sound() { return "Woof!"; } + + /** + * Returns the Doggo's price. + * + * @return An int representing the Doggo's price in dollars. + */ + @Override + public int getPrice() { return this.price; } + + /** + * Gives a good Doggo a treat. + * + * @param count An int representing the amount of treats to give. + */ + public void feedTreat(int count) { + this.happiness = Math.min(this.happiness + 5 * count, 100); + this.price += this.price + count; + } + + /** + * Punishes the bad Doggo. + * + * @param harshness An int representing the degree of harshness for punishment. + */ + public void punishment(int harshness) { + this.happiness = Math.max(this.happiness - harshness, 0); + this.price = Math.max(Math.round(this.price - harshness / 10.0f), 5); + } + + /** + * Return's the Doggo's happiness rating from 0-100. + * + * @return An int representing the Doggo's happiness rating. + */ + public int getHappiness() { + return this.happiness; + } + + /** + * Returns a String representing the Doggo. + * + * @return A String representing Doggo. + */ + @Override + public String toString(){ + return super.toString() + " (Doggo has happiness rating of " + this.happiness + "!) "; + } +} diff --git a/src/main/java/Trader.java b/src/main/java/Trader.java index 7d4d1f4..35a9160 100644 --- a/src/main/java/Trader.java +++ b/src/main/java/Trader.java @@ -96,8 +96,10 @@ public static void main(String[] args) { List all_items = Arrays.asList( new Horse(), new Horse(), - new Horse() - // TODO: Add Tradable objects here! + new Horse(), + // Add Tradable objects here! + new Doggo(), + new Doggo() ); /* Below, we've created two Traders. Their money, inventory, and diff --git a/src/test/java/DoggoTest.java b/src/test/java/DoggoTest.java new file mode 100644 index 0000000..72f3b14 --- /dev/null +++ b/src/test/java/DoggoTest.java @@ -0,0 +1,42 @@ +/* This file does the testing for Doggo.java. + */ + +import org.junit.*; +import static org.junit.Assert.*; + +public class DoggoTest { + Doggo dog; + + @Before + public void setUp() throws Exception { + dog = new Doggo(); + } + + @Test(timeout = 50) + public void TestSound() { + assertEquals("Woof!", dog.sound()); + } + + @Test(timeout = 50) + public void TestGetHappiness() { + assertEquals(10, dog.getHappiness()); + } + + @Test(timeout = 50) + public void TestFeedTreat() { + dog.feedTreat(8); + assertEquals(50, dog.getHappiness()); + } + + @Test(timeout = 50) + public void TestPunishment() { + dog.punishment(100); + assertEquals(0, dog.getHappiness()); + } + + @Test(timeout = 50) + public void TestGetPrice() { + assertEquals(5, dog.getPrice()); + } + +}