I am a beginning java programmer that is working on an invoicing program. This program has a method that figures out what boxes to use to ship a product. Here are the requirements of this method:
30 products fit in a large box
20 products fit in a medium box
10 products fit in a small box
As of right now, I am trying to use while statements to add the total for each boxes. I'm not sure if this is the right approach or not, but hopefully, if it's not, you can guide me in the right direction.
When I click the create invoice button, this code executes along with the other needed methods to create the invoice.
Here is the code:
while (totalBags >= 30 && totalBags > 0)
lgBoxes = lgBoxes + 1;
totalBags = totalBags - 30;
while (totalBags <= 20 && totalBags > 10)
medBoxes = medBoxes + 1;
totalBags = totalBags - 20;
while (totalBags <= 10 && totalBags > 0)
smBoxes = smBoxes + 1;
totalBags = totalBags - 10;
When I put in 315 products, the program should pick 10 large boxes, 1 medium, and 0 small boxes, but instead, it picks 10 large boxes, 0 medium, and 0 small.
What do I have to do to fix this issue?
Thank you in advance for your help!