From 2ba157f553d0264166aac1b11737c43c0d1674ac Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Mon, 2 Feb 2015 03:00:07 -0500 Subject: [PATCH] added new methods as well as group discussion questions in the comments --- MerchantRPGCSE2102/src/game/Merchant.java | 61 ++++++++++++++++++----- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/MerchantRPGCSE2102/src/game/Merchant.java b/MerchantRPGCSE2102/src/game/Merchant.java index 5408762..f752f50 100644 --- a/MerchantRPGCSE2102/src/game/Merchant.java +++ b/MerchantRPGCSE2102/src/game/Merchant.java @@ -1,12 +1,19 @@ package game; +import java.util.Random; + public class Merchant { private String _name; private int _currentCash; private int _baseCash; + private int _dailyRandomPrice; + //************************************************************* + //should we use an array of items or maybe a linked list? + //further discussion with group needed private Item[] _inventory; - + //************************************************************* + //merchant constructor public Merchant(String name, int cashLimit, int inventorySize) { @@ -14,6 +21,8 @@ public Merchant(String name, int cashLimit, int inventorySize) _currentCash = cashLimit; _baseCash = cashLimit; _inventory = new Item[inventorySize]; + //placeholder number + _dailyRandomPrice = 0; } //will restore the current Cash amount back to the base amount @@ -22,14 +31,14 @@ 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) { @@ -49,34 +58,62 @@ public int decrementCash(int decrementAmount) return _currentCash; } } - + //randomizer - //incomplete method - public int randomizer() + //will generate a number between 0 and max + public int randomizer(int max) + { + int randomNumber = 0; + Random randomGenerator = new Random(); + randomNumber = randomGenerator.nextInt(max); + return randomNumber; + } + + //will set the dailyRandomPrice to a number between the two given inputs + public void setDailyRandomPrice(int minPercent, int maxPercent) { - //placeholder variable - int randomOutput = 0; - return randomOutput; + int randomizerVar = maxPercent - minPercent; + _dailyRandomPrice = randomizer(randomizerVar) + minPercent; } + //************************************************************************ + //given the name of the item then it will return + //the price of the item + //incomplete method + 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; + } + //************************************************************************ + //name getter public String getName() { return _name; } - + //current cash getter public int getCurrentCash() { return _currentCash; } - + //base cash getter public int getBaseCash() { return _baseCash; } - + + //dailyRandomPrice getter + public int getRandomPrice() + { + return _dailyRandomPrice; + } + //inventory getter public Item[] getInventory() {