Skip to content

Commit

Permalink
Built the TestItem class and flushed out the skeleton of the Item Class
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Feb 3, 2015
1 parent cd697e5 commit d49f310
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
66 changes: 66 additions & 0 deletions MerchantRPGCSE2102/src/game/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,71 @@

public class Item
{
private String _name;
private int _basePrice;
private int _maxPrice;
private int _minPrice;
private int _adjustedPrice;

//Item constructor
public Item(String itemName, int basePrice, int maxPrice, int minPrice)
{
_name = itemName;
_basePrice = basePrice;
_maxPrice = maxPrice;
_minPrice = minPrice;
_adjustedPrice = _basePrice;
}

//will set the adjusted price of the item based off of the daily percent of the merchant
//will need the daily percent as an input from merchant
//if the adjusted price is less than the minPrice, then it will return the minPrice and set it as the adjusted
//if greater than the max price, the adjusted will be the maxPrice and maxPrice is returned
//else it will set the price as the floor and return
public int setAdjPrice(double merchantPercent)
{
//will find the floor of the price to prevent decimals
int calculatedPrice = (int) Math.floor((merchantPercent / 100) * _basePrice);

//checks if the calculated price is greater or less than the given bounds
if(calculatedPrice > _maxPrice)
_adjustedPrice = _maxPrice;
else if(calculatedPrice < _minPrice)
_adjustedPrice = _minPrice;
//if within bounds, then returns the calculated price
else
_adjustedPrice = calculatedPrice;

return _adjustedPrice;
}

//name getter
public String getItemName()
{
return _name;
}

//base price getter
public int getBasePrice()
{
return _basePrice;
}

//max price getter
public int getMaxPrice()
{
return _maxPrice;
}

//min price getter
public int getMinPrice()
{
return _minPrice;
}

//adjusted price getter
public int getAdjustedPrice()
{
return _adjustedPrice;
}
}
27 changes: 27 additions & 0 deletions MerchantRPGCSE2102/src/tests/TestItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package tests;

import game.Item;
import junit.framework.TestCase;

public class TestItem extends TestCase
{
private Item i;

public void setup()
{
i = new Item("Test", 100, 150, 50);
}

public void testAdjustedPrice()
{
setup();
int testPrice = i.setAdjPrice(80);
assertEquals(80, testPrice);
testPrice = i.setAdjPrice(120);
assertEquals(120, testPrice);
testPrice = i.setAdjPrice(200);
assertEquals(150, testPrice);
testPrice = i.setAdjPrice(0);
assertEquals(50, testPrice);
}
}

0 comments on commit d49f310

Please sign in to comment.