From e53a0fb5e63ea077c100f4796341ef70d2ea7c70 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 1 Mar 2015 13:12:05 -0500 Subject: [PATCH] Updated TransactionUI to address the known bugs --- MerchantRPGCSE2102/src/model/Player.java | 4 ++-- MerchantRPGCSE2102/src/view/TransactionUI.java | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/MerchantRPGCSE2102/src/model/Player.java b/MerchantRPGCSE2102/src/model/Player.java index 3ce3a68..dc6a9a6 100644 --- a/MerchantRPGCSE2102/src/model/Player.java +++ b/MerchantRPGCSE2102/src/model/Player.java @@ -94,10 +94,10 @@ public boolean sell(String itemName, Merchant targetMerchant, int amount) throws return true; } else - throw new MerchantNotEnoughCashException(); + return false; } else - return false; + throw new MerchantNotEnoughCashException(); } /** diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index 180cf05..bd72d3e 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -228,11 +228,12 @@ public static void createSellWindow() frame.setContentPane(contentPane); contentPane.setLayout(null); - String[] itemList = new String[MASTER.getPlayer().getInventory().length]; //create a new array of strings with the length of the player's inventory //item that the player chooses from the combobox + String[] itemList = new String[MASTER.getTargetMerchant().getInventory().length]; //create a new array of strings with the length of the player's inventory for(int i = 0; i < itemList.length; i++) //adds all the item names to the item list { - itemList[i] = MASTER.getPlayer().getInventory()[i].getItemName(); - itemList[i] = itemList[i] + " (x" + MASTER.getPlayer().getInventory()[i].getQuantity() + ")"; + itemList[i] = MASTER.getTargetMerchant().getInventory()[i].getItemName(); + itemList[i] = itemList[i] + " (x" + MASTER.getPlayer().getInventory()[i].getQuantity() + ")"; //appends the quantity of items that the player has + itemList[i] = itemList[i] + " ($" + MASTER.getTargetMerchant().getInventory()[i].getAdjustedPrice() + ")"; //appends the price of the item } JLabel lblYouHave = new JLabel(MASTER.getTargetMerchant().getName() + " has: $" + MASTER.getTargetMerchant().getCurrentCash()); @@ -289,12 +290,12 @@ public void mouseClicked(MouseEvent e) { //information is consumed w else throw new NumberFormatException(); //will throw a NumberFormatException if actionSell returns a false } - catch(NumberFormatException exception){ - System.out.println("Must input a number less than or equal to the total amount of the item that you have"); + catch(MerchantNotEnoughCashException mnecexception){ + System.out.println("Merchant does not have enough cash"); } } - catch(MerchantNotEnoughCashException mnecexception){ - System.out.println("Merchant does not have enough cash"); + catch(NumberFormatException exception){ + System.out.println("Must input a number less than or equal to the total amount of the item that you have"); } } catch(NotInInventoryException niiexception){