Answer to Question #327666 in Java | JSP | JSF for Jeffrey

Question #327666

Write a program to calculate the correct packaging system for chocolates.  A user has the option to put it in a box, or put it in a box inside a container.  A box of chocolate bars can hold 30 bars and a container can hold 94 boxes of chocolates. Write a program that prompts the user to enter the total number of chocolate bars. The program then outputs the number of boxes and/or the number of containers to ship the chocolates. Note that each box must contain the specified number of chocolates each container must contain the specified number of boxes. If the last box of chocolates contains less than the number of specified chocolates you can discard it, and output the number of leftover chocolate. Similarly, if the last container contains less than the number of specified boxes, you can discard it, and output

the number of leftover boxes.


1
Expert's answer
2022-04-13T16:05:08-0400
import java.util.Scanner;

public class Chocolate {
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        Scanner z=new Scanner(System.in);
        System.out.println("Choose boxes or containers: ");
        String userChose=s.next();
        System.out.println("Enter the total number of chocolate bars");
        int userChose2=z.nextInt();
        if(userChose.contains("con")){
            if(userChose2%2820==0){
                int containers=userChose2/2820;
                System.out.println("You need: "+containers+" containers" );
            }
            else{
                int q=userChose2/2820;
                System.out.println("Ypu need "+q+" containers");
            }
        }
        else {
            if(userChose2%30==0){
                int boxes=userChose2/30;
                System.out.println("You need: "+ boxes+" boxes");
            }
            else{
                int w=userChose2/30;
                System.out.println("You need: "+ w +" boxes");
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS