Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int totalBoxes = 324;
- final int CONTAINER_CAPACITY = 27;
- final int CAR_CAPACITY = 12 * CONTAINER_CAPACITY; //in boxes
- for (int i = 0; i < totalBoxes; ) {
- if (isNewSpaceNeeded(i, CAR_CAPACITY)) {
- System.out.println("Car N " + (countSpaceObjects(i, CAR_CAPACITY) + 1));
- }
- if (isNewSpaceNeeded(i, CONTAINER_CAPACITY)) {
- System.out.println(" Container N " + (countSpaceObjects(i, CONTAINER_CAPACITY) + 1));
- }
- i++;
- System.out.println(" Box N " + i);
- if (i == totalBoxes) {
- System.out.println("Total cars needed " + countSpaceObjects(i, CAR_CAPACITY));
- System.out.println("Total containers needed " + countSpaceObjects(i, CONTAINER_CAPACITY));
- System.out.println("Total boxes " + i);
- }
- }
- }
- private static boolean isNewSpaceNeeded(int items, int spaceCapacity) {
- return items % spaceCapacity == 0;
- }
- private static int countSpaceObjects(int items, int spaceCapacity) {
- return items / spaceCapacity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement