Guest User

Untitled

a guest
Apr 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. public void restockProduct(String product, int quantity)
  2. { //SOMETHING IS WRONG WITH THIS :(
  3. int totalFreeSpace = 0;
  4. for (int i = 0; i < numslots; i++)
  5. {
  6. if (product.equals(this.product[i]))
  7. {
  8. totalFreeSpace += (this.maxperslot - this.quantity[i]);
  9. }
  10. }
  11. System.out.println("totalFreeSpace: " + totalFreeSpace);
  12.  
  13. if (totalFreeSpace >= quantity)
  14. {
  15. int remainder = 0;
  16. for (int i = 0; i < numslots; i++)
  17. {
  18. if (product.equals(this.product[i]))
  19. {
  20. if (quantity <= (this.maxperslot - this.quantity[i]))
  21. {
  22. this.quantity[i] += quantity;
  23. quantity = 0;
  24. }
  25. else if (quantity > (this.maxperslot - this.quantity[i]))
  26. {
  27. remainder = quantity - this.quantity[i];
  28. quantity = remainder;
  29. this.quantity[i] += (this.maxperslot - this.quantity[i]);
  30. }
  31. System.out.println("quantity: " + this.quantity[i]);
  32. }
  33. }
  34. }
  35. }
Add Comment
Please, Sign In to add comment