-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created skeleton for the Merchant class, built a testMerchant class and
created some tests for the Merchant class.
- Loading branch information
Gavin Li
committed
Feb 2, 2015
1 parent
00d7c4f
commit 5d92fc3
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
public class Item | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |