• Post Reply Bookmark Topic Watch Topic
  • New Topic

Total Inventory Value not the same for each button

 
Amie Mac
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Morning...
I am working on Part 5 of my Inventory Program. I have everything working except that the Total Inventory Value changes. It will show one value when I click on First, then it will show another value when I click on Last, then it will go up and finally settle on a different value when I iterate through the array with the first and next buttons. I am hoping someone can tell me why this is happening... Thanks

The buttons are placed in the InventoryLauncher.java file
Calling the totalInventoryValue from the Inventory.java file


Here's the code:

InventoryLauncher.java


Inventory.java


Books.java
 
Knute Snortum
Sheriff
Posts: 3257
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amie Mac
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


So, if I have a method and then have totalInventoryValue listed once instead of on each button, would that help?
 
Knute Snortum
Sheriff
Posts: 3257
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Amie Mac
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


Yes, books extends inventory and the inventoryValue() method in books overrides the one in inventory. Do I have that wrong?
 
Knute Snortum
Sheriff
Posts: 3257
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amie Mac
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Thanks for spotting this! I changed it to:

and added the restockingFee() method in the inventoryValue() method.

Works great!

Thanks again!
 
Knute Snortum
Sheriff
Posts: 3257
84
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!