From 5d92fc3939c4cd7e15a632561f1bd6ecec442ae1 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 1 Feb 2015 19:30:20 -0500 Subject: [PATCH] Created skeleton for the Merchant class, built a testMerchant class and created some tests for the Merchant class. --- MerchantRPGCSE2102/src/Item.java | 5 ++ MerchantRPGCSE2102/src/Merchant.java | 83 ++++++++++++++++++++++++ MerchantRPGCSE2102/src/testMerchant.java | 35 ++++++++++ 3 files changed, 123 insertions(+) create mode 100644 MerchantRPGCSE2102/src/Item.java create mode 100644 MerchantRPGCSE2102/src/Merchant.java create mode 100644 MerchantRPGCSE2102/src/testMerchant.java diff --git a/MerchantRPGCSE2102/src/Item.java b/MerchantRPGCSE2102/src/Item.java new file mode 100644 index 0000000..4590472 --- /dev/null +++ b/MerchantRPGCSE2102/src/Item.java @@ -0,0 +1,5 @@ + +public class Item +{ + +} diff --git a/MerchantRPGCSE2102/src/Merchant.java b/MerchantRPGCSE2102/src/Merchant.java new file mode 100644 index 0000000..4ea2285 --- /dev/null +++ b/MerchantRPGCSE2102/src/Merchant.java @@ -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; + } +} diff --git a/MerchantRPGCSE2102/src/testMerchant.java b/MerchantRPGCSE2102/src/testMerchant.java new file mode 100644 index 0000000..18a9aac --- /dev/null +++ b/MerchantRPGCSE2102/src/testMerchant.java @@ -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()); + } +}