Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         int totalBoxes = 12;
  4.  
  5.         final int CONTAINER_CAPACITY = 27;
  6.         final int CAR_CAPACITY = 12 * CONTAINER_CAPACITY; //in boxes
  7.  
  8.         for (int i = 0; i < totalBoxes; ) {
  9.             if (isNewSpaceNeeded(i, CAR_CAPACITY)) {
  10.                 System.out.println("Car N " + countSpaceObjects(i, CAR_CAPACITY));
  11.             }
  12.             if (isNewSpaceNeeded(i, CONTAINER_CAPACITY)) {
  13.                 System.out.println("    Container N " + countSpaceObjects(i, CONTAINER_CAPACITY));
  14.             }
  15.             i++;
  16.             System.out.println("        Box N " + i);
  17.  
  18.             if (i == totalBoxes) {
  19.                 System.out.println("Total cars needed " + (countSpaceObjects(i, CAR_CAPACITY) - (isNewSpaceNeeded(i, CAR_CAPACITY) ? 1 :
  20.                         0)));
  21.                 System.out.println("Total containers needed " + (countSpaceObjects(i, CONTAINER_CAPACITY) - (isNewSpaceNeeded(i, CAR_CAPACITY) ? 1 :
  22.                         0)));
  23.                 System.out.println("Total boxes  " + i);
  24.             }
  25.         }
  26.     }
  27.  
  28.     private static boolean isNewSpaceNeeded(int items, int spaceCapacity) {
  29.         return items % spaceCapacity == 0;
  30.     }
  31.  
  32.     private static int countSpaceObjects(int items, int spaceCapacity) {
  33.         return items / spaceCapacity + 1;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement