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.
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");
}
}
}
}
Comments
Leave a comment