KnowledgeBoat Logo

Computer Applications

A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Write a program that prompts the user to enter the total number of cookies, the number of cookies in each box, and the number of cookies boxes in a container. The program then outputs the number of boxes and the number of containers required to ship the cookies.

Java

Java Conditional Stmts

36 Likes

Answer

import java.util.Scanner;

public class KboatCookies
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter total no. of cookies: ");
        int cookieCount = in.nextInt();
        System.out.print("Enter no. of cookies per box: ");
        int cookiePerBox = in.nextInt();
        System.out.print("Enter no. of boxes per container: ");
        int boxPerContainer = in.nextInt();
        
        int numBox = cookieCount / cookiePerBox;
        if (cookieCount % cookiePerBox != 0)
            numBox++;
            
        int numContainer = numBox / boxPerContainer;
        if (cookieCount % cookiePerBox != 0)
            numContainer++;
            
        System.out.println("No. of boxes = " + numBox);
        System.out.println("No. of containers = " + numContainer);
    }
}

Output

BlueJ output of A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Write a program that prompts the user to enter the total number of cookies, the number of cookies in each box, and the number of cookies boxes in a container. The program then outputs the number of boxes and the number of containers required to ship the cookies.

Answered By

20 Likes


Related Questions