Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A box of cookies can hold 24 cookies and a container can hold 75 boxes of cookies. Write a program in Java that prompts the

A box of cookies can hold 24 cookies and a container can hold 75 boxes of cookies. Write a program in Java that prompts the user to enter the total number of cookies. The program then outputs the number of boxes and the number of containers in which to ship the cookies. Note that each box must contain the specified number of cookies and each container must contain the specified number of boxes. If the last box of cookies contains less than the number of specified cookies, you can discard it, and output the number of leftover cookies. Similarly, if the last container contains less than the number of specified boxes, you can discard it, and output the number of leftover boxes. Instructions: 1. Create a second class named CookieCalculator. This class should have one private variable member that will hold the number of cookies to be shipped. The class should have two constructors; one that takes no arguments and a second that take a single argument that is the number of cookies to be shipped. You will also need to create a get and set method for the private variable member. 2. The Main class will contain two methods. The main method will prompt the user for the number of cookies to be shipped and then call a second method that will create an object of type CookieCalculator to output the appropriate information to the user. This object should and set its private member to be equal to the number entered by the user. (You may do this through the constructor or by calling the set method on the private variable). The prompt to the user should be created using the JOptionPane dialog boxes discussed in class. 3. Write a method, in the CookieCalculator class, that will calculate the number boxes that will be used. This method should return a value that is the number of boxes that will be required and it should take no arguments. 4. Write a method, in the CookieCalculator class, that will calculate the number of containers that will be used. This method should return a value that is the number of containers that will be required and it should take no arguments. 5. Write a method, in the CookieCalculator class, that will calculate the number of cookies left over. This method should return a value that is the number of cookies that will be left over and it should take no arguments. 6. Write a method, in the CookieCalculator class, that will calculate the number of boxes left over. This method should return a value that is the number of Boxes that will be left over and it should take no arguments. 7. Using the IF statement learned in class write statements that will check to see if there are any leftover cookies or boxes. You should output messages about leftover cookies and boxes only if they exist. A statement that zero cookies/boxes were left over should never be displayed to the user. 8. You must also display the total number of boxes and containers used to ship the cookies. 9. All output should be done using JOptionPane discussed in class Example Input/Output: Example 1 (no leftovers) Please enter the number of cookies to be shipped: 9000 Shipping Details: Number of boxes shipped: 375 Number of containers shipped: 5 Example 2 (with leftovers) Please enter the number of cookies to be shipped: 6000 Shipping Details: Number of boxes shipped: 250 Number of containers shipped: 3 Leftover boxes: 25

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Robb,Carlos Coronel

5th Edition

061906269X, 9780619062699

More Books

Students also viewed these Databases questions