Skip to content

Commit

Permalink
Merchant class updates:
Browse files Browse the repository at this point in the history
*created search method that returns the item based off the inputted
string name. Also finished the getItemPrice method to return the
adjusted price of the item given a the name of the item
  • Loading branch information
Gavin Li committed Feb 10, 2015
1 parent 93c8bfc commit 1b66563
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
28 changes: 19 additions & 9 deletions MerchantRPGCSE2102/src/game/Merchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
5 changes: 5 additions & 0 deletions MerchantRPGCSE2102/src/tests/TestMerchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,9 @@ public void testName() throws Exception
setup();
assertEquals("Test", m.getName());
}

public void testSearch() throws Exception
{

}
}

0 comments on commit 1b66563

Please sign in to comment.