Skip to content

Commit

Permalink
Updated Merchant and TestMerchant Classes:
Browse files Browse the repository at this point in the history
*added a method to adjust the prices for all items in the merchant's
inventory. updated TestMerchant to test the new method.
  • Loading branch information
Gavin Li committed Feb 10, 2015
1 parent 1b66563 commit 6b60f82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions MerchantRPGCSE2102/src/game/Merchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public Merchant(String name, int cashLimit, ArrayList<String> inventory)
generateMerchantInventory(inventory);
_dailyRandomPercent = 0; //placeholder percentage
}

//will generate an array of items based off an ArrayList of item names
//saves the array to _inventory
private void generateMerchantInventory(ArrayList<String> itemList)
Expand All @@ -29,7 +29,7 @@ private void generateMerchantInventory(ArrayList<String> itemList)
String[] nameAndPrice;
String name;
String price;

for(int i=0; i < itemList.size(); i++)
{
nameAndPrice = itemList.get(i).split("\\s+"); //splits the string into the string name and string price
Expand Down Expand Up @@ -89,7 +89,7 @@ public void setDailyRandomPrice(int minPercent, int maxPercent)
int randomizerRange = maxPercent - minPercent;
_dailyRandomPercent = randomizer(randomizerRange) + minPercent;
}

//given the name of the item then it will return
//the adjusted price of the item
public int getItemPrice(String itemName)
Expand All @@ -109,11 +109,20 @@ public Item getItem(String itemName)
if(_inventory[i].getItemName().equals(itemName))
return _inventory[i];
}

System.out.println("No such item exists");
return null;
}


//will set adjusted prices for all of the items in the inventory
public void setAllAdjustedPrices()
{
for(Item i: _inventory)
{
i.setAdjPrice(_dailyRandomPercent);
}
}

//name getter
public String getName()
{
Expand Down
10 changes: 10 additions & 0 deletions MerchantRPGCSE2102/src/tests/TestMerchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public void testInventory() throws Exception
}
}

//testing inventory prices
public void testInventoryPrices() throws Exception
{
setup();
m.setAllAdjustedPrices();
assertEquals(0, m.getItemPrice("water"));
assertEquals(0, m.getItemPrice("armor"));
assertEquals(0, m.getItemPrice("food"));
}

//testing name
public void testName() throws Exception
{
Expand Down

0 comments on commit 6b60f82

Please sign in to comment.