Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         int totalBoxes = 324;
  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) + 1));
  11.             }
  12.             if (isNewSpaceNeeded(i, CONTAINER_CAPACITY)) {
  13.                 System.out.println("    Container N " + (countSpaceObjects(i, CONTAINER_CAPACITY) + 1));
  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));
  20.                 System.out.println("Total containers needed " + countSpaceObjects(i, CONTAINER_CAPACITY));
  21.                 System.out.println("Total boxes  " + i);
  22.             }
  23.         }
  24.     }
  25.  
  26.     private static boolean isNewSpaceNeeded(int items, int spaceCapacity) {
  27.         return items % spaceCapacity == 0;
  28.     }
  29.  
  30.     private static int countSpaceObjects(int items, int spaceCapacity) {
  31.         return items / spaceCapacity;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement