diff --git a/MerchantRPGCSE2102/src/game/Merchant.java b/MerchantRPGCSE2102/src/game/Merchant.java index 9b9ed11..6256c8c 100644 --- a/MerchantRPGCSE2102/src/game/Merchant.java +++ b/MerchantRPGCSE2102/src/game/Merchant.java @@ -90,20 +90,30 @@ public void setDailyRandomPrice(int minPercent, int maxPercent) _dailyRandomPercent = randomizer(randomizerRange) + minPercent; } - //************************************************************************ //given the name of the item then it will return - //the price of the item - //incomplete method + //the adjusted price of the item public int getItemPrice(String itemName) { - //placeholder return - //should discuss best way to organize the item array to - //minimize the runtime needed to look up the items - int placeHolder = 0; - return placeHolder; + Item targetItem = getItem(itemName); + int itemPrice = targetItem.getAdjustedPrice(); + return itemPrice; } - //************************************************************************ + //given the item name, it will search through the merchant's inventory and return the item + //if it cannot be found, it will return null and output an error message + //big O(n) runtime + public Item getItem(String itemName) + { + for(int i = 0; i < _inventory.length; i++) + { + if(_inventory[i].getItemName().equals(itemName)) + return _inventory[i]; + } + + System.out.println("No such item exists"); + return null; + } + //name getter public String getName() { diff --git a/MerchantRPGCSE2102/src/tests/TestMerchant.java b/MerchantRPGCSE2102/src/tests/TestMerchant.java index 32d8261..49eb195 100644 --- a/MerchantRPGCSE2102/src/tests/TestMerchant.java +++ b/MerchantRPGCSE2102/src/tests/TestMerchant.java @@ -64,4 +64,9 @@ public void testName() throws Exception setup(); assertEquals("Test", m.getName()); } + + public void testSearch() throws Exception + { + + } }