could you revise this as it appears to not compile?

Ohea2345
timer Asked: Sep 18th, 2015

Question Description

revise..txt 

Unformatted Attachment Preview

public class Inventory { /** * Fill this id in so the marking system looks pretty (and you get marks) */ public static String studentEmailID = "smirs001"; //eg smirs001 /** * Item list. This contains the list of all items. * The list should never contain a null in the middle and should never have a * blank at the end (eg a null). */ private Item[] itemList = new Item[0]; /** * NOTE DO NOT CREATE ANY OTHER VARIABLES HERE */ /** * The number of coins in the inventory */ private int goldCoins=0; /** * Maximum carrying capacity * */ double maximumCarryingCapacity = 0; /** * Maximum number of items; */ int maximumNumberOfItems = 0; /** * Name of inventory */ String name = null; public Inventory() { } /** * Increase the array by one. You will need to create a new array one element * bigger than the old array. * No External Classes Permitted to Be Used in This Method * My Solution Length in Lines (note yours can be longer or shorter): 4 * */ private void increaseArray() { Item[] temp = new Item[itemList.length + 1]; for (int i = 0; i < itemList.length; i++) { [i] = itemList[i]; } itemList = temp; } /** * shrink the array by one. You will need to create a new array one smaller * than the current one then copy the old one into the new one. * This method should fail if the list is less than 1 in size, also if the last * element is not null. * No External Classes Permitted to Be Used in This Method * My Solution Length in Lines (note yours can be longer or shorter): 9 * * @return true if it was successful false if unsuccessful */ private boolean decreaseArray() { if (itemList.length < 1 || itemList) return false; } /** * @param myItem first item to compare * @param theirItem second item to compare * @return the difference in current values between item 1 and item 2 -1 if either were nulls */ static double tradeItemCalculation(Item myItem, Item theirItem) { if (myItem == null || theirItem == null) return -1; return myItem.getCurrentValue() - theirItem.getCurrentValue(); } /** * Return the item at the specific location in the list * If the item doesn't exist return null. * This does not modify the item list. It will return * No External Classes Permitted to Be Used in This Method * My Solution Length in Lines (note yours can be longer or shorter): 5 * * @param index the position to return. * @return The item at index or null if no item */ //ALL METHODS FROM HERE ON ARE REMOVED YOU NEED TO ADD THEM IN. public Item itemAt(int index) { return itemList[index]; } } /** * Add gold to the inventory. * My Solution Length in Lines (note yours can be longer or shorter): 1 * * @param amountToAdd add the gold to the inventory */ void addGold(int amountToAdd) { goldCoins += amountToAdd; /** * remove gold from inventory. * If you ask for more than you got in the inventory * return -1 to flag that its not possible to remove gold * else remove the gold and return the amount you removed * from the inventory. * My Solution Length in Lines (note yours can be longer or shorter): 6 * * @param amountToRemove The amount of gold to remove from the inventory * @return the amount removed unless it would have gone negative then -1 */ public int removeGold(int amountToRemove) { if (goldCoins < amountToRemove) { return -1; } else { return amountToRemove; } } /** * Returns the current gold coins in the inventory * Not tested in Junit * My Solution Length in Lines (note yours can be longer or shorter): 1 * * @return amount of gold in kitty */ public int getGold() { } return goldCoins; /** * Adds the provided item to the array. You will need to increase * the array size and add the new item to the end of the list. If the * name already exists (case does not matter) don't add the item. * No External Classes Permitted to Be Used in This Method Apart From * String.toUpperClass and String.Equals * If the item status is broken do not add it to the list * My Solution Length in Lines (note yours can be longer or shorter): 6 * * @param newItem the item to be added * @return the index of the new item -1 if newItem was null, null or its broken */ int addItem(Item newItem) { if (newItem == null || "BROKEN".equals(newItem.getStatus())) return -1; increaseArray(); for (int i = 0; i < itemList.length - 1; i++) { if (newItem.getName().equals(itemList[i].getName())) return -1; } itemList[itemList.length - 1] = newItem; maximumNumberOfItems++; return itemList.length - 1; } /** * remove the item at the index. * Pack the array and shrink the array when finished. * No External Classes Permitted to Be Used in This Method * My Solution Length in Lines (note yours can be longer or shorter): 8 * * @param index of the item to remove * @return the item removed. If no item at the index return null. * */ public Item removeItem(int index) { if (index > itemList.length - 1) { return null; } else { Item[] temp = new Item[itemList.length - 1]; int j = 0; for (int i = 0; i < itemList.length; i++) { if (i != index) { [j] = itemList[i]; ++; } } itemList = temp; return itemList[index]; } } /** * remove the item of name from the array. * Pack the array and shrink the array when finished. * case shouldn't matter. * (Note that you should do this method by using other methods) * No External Classes Permitted to Be Used in This Method * My Solution Length in Lines (note yours can be longer or shorter): 1 * * @param nameOfItem The name of the item to be remove * @return the item removed. If no item at the index return null. */ public Item removeItem(String nameOfItem) { Item[] temp = new Item[itemList.length - 1]; int j = 0; Item itemFound = null; for (int i = 0; i < itemList.length; i++) { if (itemList[i].getName().toLowerCase() != nameOfItem.toLowerCase()) { [j] = itemList[i]; ++; } else { = itemList[i]; } } itemList = temp; return itemFound == null ? null : itemFound; } /** * returns a list of broken items. * if there are no broken items return an empty list. * No External Classes Permitted to Be Used in This Method. * My Solution Length in Lines (note yours can be longer or shorter): 13 * * @return a list of items that are broken. If there is nothing in the list return empty item array. */ public Item[] brokenItems() { int totalBrokenItems = 0; for (int i = 0; i < itemList.length; i++) { if (itemList[i].isBroken()) { ++; } } Item[] brokenItems = new Item[totalBrokenItems]; int j = 0; for (int i = 0; i < itemList.length; i++) { [j] = itemList[i]; ++; } return brokenItems; } /** * Damage the particular item at the index. If the item is destroyed (eg damage greater * than the durability of the item. The item should be left in the list with status updated to broken. * No External Classes Permitted to Be Used in This Method Apart from String.equals. * My Solution Length in Lines (note yours can be longer or shorter): 3 * * @param index the item to damage * @param damage the amount of damage * @return true if the item was broken false if not found or not broken */ public boolean damageItem(int index, double damage) { if (index > itemList.length - 1) { return false; } else { Item item = itemList[index]; .setBroken((item.getDamage() + damage) > item.getDurability() ? true : false); } itemList[index] = item; return item.isBroken(); /** * find the item with the particular name. * Leave the item in the list and get a copy. * No External Classes Permitted to Be Used in This Method Apart from String.equals * My Solution Length in Lines (note yours can be longer or shorter): 3 * * @param nameToBeFound the name of the item to be found * @return the item with the name or null if not found */ public Item getItem(String nameToBeFound) { for (int i = 0; i < itemList.length; i++) { if (itemList[i].getName().toLowerCase() == nameToBeFound.toLowerCase()) { return itemList[i]; } } return null; } /** * Repair the item of the name. * * The item will be repaired only if there is enough gold in the inventory * to pay for it. * * The cost of the repair is 25% of the lost value of the durability * For example * If you had a widget that was worth 1000 gold coins * and it was at 60% durability then its current value is 600 gold coins. * It has lost 400 gold coins in value due to wear. * If you repair the item it will cost 100 gold coins (25% of 400 gold coins). * * If there is not enough gold to repair the item it should not repair the item * at all and return false. Otherwise it should remove the gold coins from the * inventory and return true. * My Solution Length in Lines (note yours can be longer or shorter): 3 * * @param nameToBeRepaired the name of the item to be repaired * @return true if successfully repaired false otherwise */ public boolean repairItem(String nameToBeRepaired) { Item item = this.getItem(nameToBeRepaired); double percentDamaged = (item.getDamage() * 100) / item.getDurability(); double valueDamaged = item.getValue() * percentDamaged; int costOfRepair = (int) (0.25 * valueDamaged); if (costOfRepair goldCoins) return false; goldCoins -= item.repairCost(); return true; } /** * return the index of the item with the given name. Case does not matter. * No External Classes Permitted to Be Used in This Method Apart from * String.Equals and String.ToUpperCase * My Solution Length in Lines (note yours can be longer or shorter): 6 * * @param nameToBeFound the name of the item to be found * @return the position of the searched for item. -1 if none found * * @param nameToBeRepaired the name of the item to be repaired * @return true if successfully repaired false otherwise */ boolean repairItem(String nameToBeRepaired) { if (nameToBeRepaired == null) return false; int i = 0; for (; i < itemList.length; i++) { if (nameToBeRepaired.toUpperCase().equals(itemList[i].getName())) break; } return repairItem(i); } /** * ADVANCED STUDENTS ONLY * * Sort the array by item name. Note that if you are not attempting this method * you must still implement the method signature so that the test program will run. * No External Classes Permitted to Be Used in This Method Apart From String.CompareToIgnoreCase * My Solution Length in Lines (note yours can be longer or shorter): 12 * */ public void sort() { } /** * Creates a * * Item List * 1. output * 2. output * 3. output list of item with their hit points in the following form of item toStringMethod of item toStringMethod of item toStringMethod * 4. output of item toStringMethod * * Note the formatting is done so that the output lines up in the columns * Please use the most appropriate classes to help you do this method. * My Solution Length in Lines (note yours can be longer or shorter): 5 * */ public String toString() { String value = ""; for (int i=0;i
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors