I am trying to write a problem that calculates the number of boxes and containers based on the total number of cookies input.
Even trying to step through each line I cannot figure it out. Here's my code:
import java.util.*; public class Ch4_PrEx7 { static Scanner console = new Scanner(System.in); static final int COOKIES_PER_BOX = 24; static final int BOXES_PER_CONTAINER = 75; public static void main(String[] args) { int totalCookies = 0, numOfBoxes = 0, remainderCookies = 0, remainderBoxes = 0, numOfContainers = 0; System.out.println("Please enter the total number of cookies: "); System.out.println(); totalCookies = console.nextInt(); System.out.println("The total number of boxes needed is: " + String.format("%d%n", Boxes(totalCookies, numOfBoxes))); System.out.println("The total number of containers needed is: " + String.format("%d%n", Containers(numOfBoxes, numOfContainers))); System.out.println("The number of left over boxes is: " + String.format("%d%n", LeftOverBoxes(numOfBoxes, remainderBoxes))); System.out.println("The number of left over cookies is: " + String.format("%d%n", LeftOverCookies(totalCookies, remainderCookies))); } public static int Boxes(int totalCookies, int numOfBoxes) { numOfBoxes = totalCookies / COOKIES_PER_BOX; return numOfBoxes; } public static int Containers(int numOfBoxes, int numOfContainers) { numOfContainers = numOfBoxes / BOXES_PER_CONTAINER; return numOfContainers; } public static int LeftOverCookies(int totalCookies, int remainderCookies) { remainderCookies = totalCookies % COOKIES_PER_BOX; return remainderCookies; } public static int LeftOverBoxes(int numOfBoxes, int remainderBoxes) { remainderBoxes = numOfBoxes % BOXES_PER_CONTAINER; return remainderBoxes; } }
Thanks in advance!