Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void restockProduct(String product, int quantity)
- { //SOMETHING IS WRONG WITH THIS :(
- int totalFreeSpace = 0;
- for (int i = 0; i < numslots; i++)
- {
- if (product.equals(this.product[i]))
- {
- totalFreeSpace += (this.maxperslot - this.quantity[i]);
- }
- }
- System.out.println("totalFreeSpace: " + totalFreeSpace);
- if (totalFreeSpace >= quantity)
- {
- int remainder = 0;
- for (int i = 0; i < numslots; i++)
- {
- if (product.equals(this.product[i]))
- {
- if (quantity <= (this.maxperslot - this.quantity[i]))
- {
- this.quantity[i] += quantity;
- quantity = 0;
- }
- else if (quantity > (this.maxperslot - this.quantity[i]))
- {
- remainder = quantity - this.quantity[i];
- quantity = remainder;
- this.quantity[i] += (this.maxperslot - this.quantity[i]);
- }
- System.out.println("quantity: " + this.quantity[i]);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment