Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Doggo class and Doggo test class. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
67 changes: 67 additions & 0 deletions src/main/java/Doggo.java
Original file line number Diff line number Diff line change
@@ -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 + "!) ";
}
}
6 changes: 4 additions & 2 deletions src/main/java/Trader.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ public static void main(String[] args) {
List<Tradable> 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
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/DoggoTest.java
Original file line number Diff line number Diff line change
@@ -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());
}

}