Campbell Ritchie wrote:Why an array?
Amie Mac wrote: . . .
1. When clicking on the Add button, the button text should change to Click to Add! so the user should click it to add the item to an array
You realise the change in button text may cause the whole display to change strangelyYou can create listeners which call certain methodsBut if you are setting them editable when you push the button, how is the user supposed to enter anything beforehand? And how are you setting them uneditable?
2. When the Add button is clicked it would make the appropriate JTextFields editable . . .
Go through the JTextComponent class and its subclasses. You will probably find you can add action listeners to them, and they can be activated by pushing the enter key while the component has focus.
For things more complicated you can consider key bindings and document listeners. Also find somebody who knows more about them than I do!
Note I am not creating a Listener there but using a λ. It only works in Java8.
Paul Clapham wrote:Well, yes, there is something wrong with your question. Sorry, but it's far too long to be read and understood due to the large volume of code which is not relevant to the problem. I looked at it twice and gave up on the idea of trying to answer because of that.
So have a look at the SSCCE (Short, Self Contained, Correct (Compilable), Example) page which describes how you can produce a much better code example for your question.
Knute Snortum wrote:If you want a restocking fee in your inventory value, then you can't have a method that both sets and returns the fee. When you "next" thru the books, you're adding a fee. This changes the total inventory value.
Knute Snortum wrote:You have two inventoryValue() methods -- one on Books and one on Inventory. The Books values includes the restocking fee. Books start with no restocking fee. Calling restockingFee() both sets and returns the fee. This is bad. What if you want to just get the fee without setting it?
Knute Snortum wrote:It looks like a restocking fee is getting added to Book until all Book instances have a restocking fee. Totals change as more Books get their restocking fee added.
BTW, you have about six lines of code that get copied four times -- great place for a method.
Campbell Ritchie wrote:You are not returning the sum, but the array of inventory. You have shown the printout wrongly; there should be a [ at its beginning. You are supposed to return the BigDecimal sum and if you print it out you get a number. What you are doing is printing the array and arrays don't have an overridden toString method. So you get the same as with Object#toString.
I trust your values from the inventory are not in double format, because otherwise using BigDecimal you will simply immortalise the imprecision. Either change the inventory to use a precise form of number or round the values.
sum = sum.add(new BigDecimal(theInventory[i].inventoryValue()).round(...));
Why are you using a for loop rather than a for‑each loop?