Skip to content

Commit

Permalink
Created skeleton for the Merchant class, built a testMerchant class and
Browse files Browse the repository at this point in the history
created some tests for the Merchant class.
  • Loading branch information
Gavin Li committed Feb 2, 2015
1 parent 00d7c4f commit 5d92fc3
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MerchantRPGCSE2102/src/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

public class Item
{

}
83 changes: 83 additions & 0 deletions MerchantRPGCSE2102/src/Merchant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

public class Merchant
{
private String _name;
private int _currentCash;
private int _baseCash;
private Item[] _inventory;

//merchant constructor
public Merchant(String name, int cashLimit, int inventorySize)
{
_name = name;
_currentCash = cashLimit;
_baseCash = cashLimit;
_inventory = new Item[inventorySize];
}

//will restore the current Cash amount back to the base amount
//of cash that the merchant started the day with
public void refreshCash()
{
_currentCash = _baseCash;
}

//increments the base amount of cash that the merchant
//will start the day with
public void incrementCash(int incrementAmount)
{
_baseCash += incrementAmount;
}

//removes the specified amount from the merchant's current cash
public int decrementCash(int decrementAmount)
{
//checks if the amount attempting to be removed is
//greater than the current amount
//if true, returns null and outputs error message
if(decrementAmount > _currentCash)
{
System.out.println("Merchant has insufficent cash");
return -1;
}
//if false then removes the decrement amount
else
{
_currentCash -= decrementAmount;
return _currentCash;
}
}

//randomizer
//incomplete method
public int randomizer()
{
//placeholder variable
int randomOutput = 0;
return randomOutput;
}

//name getter
public String getName()
{
return _name;
}

//current cash getter
public int getCurrentCash()
{
return _currentCash;
}

//base cash getter
public int getBaseCash()
{
return _baseCash;
}

//inventory getter
public Item[] getInventory()
{
return _inventory;
}
}
35 changes: 35 additions & 0 deletions MerchantRPGCSE2102/src/testMerchant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import junit.framework.TestCase;


public class testMerchant extends TestCase
{
private Merchant m;

public void setup()
{
m = new Merchant("Test", 100, 2);
}

public void testCashSystem() throws Exception
{
setup();
assertEquals(-1, m.decrementCash(101));
m.incrementCash(100);
m.refreshCash();
assertEquals(200, m.getCurrentCash());
m.decrementCash(120);
assertEquals(80, m.getCurrentCash());
}

public void testInventory() throws Exception
{
setup();
assertEquals(2, m.getInventory().length);
}

public void testName() throws Exception
{
setup();
assertEquals("Test", m.getName());
}
}

0 comments on commit 5d92fc3

Please sign in to comment.