Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. An organization raises money by selling boxes of cookies. A cookie order specifies the variety of cookie and the number of boxes ordered. The

image text in transcribedimage text in transcribed

1. An organization raises money by selling boxes of cookies. A cookie order specifies the variety of cookie and the number of boxes ordered. The declaration of the cookieorder class is shown below. public class Cookieorder \{ / Constructs a new Cookieorder object. / public Cookieorder(String variety, int numBoxes) {/ implementation not shown /} / Qreturn the variety of cookie being ordered / public String getVariety () {/ implementation not shown //} / Qreturn the number of boxes being ordered / public int getnumBoxes () {/ implementation not shown /} // There may be instance variables, constructors, and methods that are not shown. \} The Masterorder class maintains a list of the cookies to be purchased. The declaration of the Masterorder class is shown below. public class Masterorder \{ / The list of all cookie orders / private List orders; / Constructs a new Masterorder object. */ public Masterorder() { orders = new ArrayList>();} / Adds theorder to the master order. * eparam theorder the cookie order to add to the master order * / public void addOrder(Cookieorder theorder) { orders.add(theorder); } / ereturn the sum of the number of boxes of all of the cookie orders / public int getTotalBoxes () {/ to be implemented in part (a) /} / Removes all cookie orders from the master order that have the same variety of * cookie as cookievar and returns the total number of boxes that were removed. * eparam cookievar the variety of cookies to remove from the master order * ereturn the total number of boxes of cookieVar in the cookie orders removed / public int removeVariety (String cookievar) {/ to be implemented in part (b) /} // There may be instance variables, constructors, and methods that are not shown. \} (a) The getTotalBoxes method computes and returns the sum of the number of boxes of all cookie orders. If there are no cookie orders in the master order, the method returns 0 . Complete method getTotalBoxes below. */ public int getTotalBoxes() b) The removeVariety method updates the master order by removing all of the cookie orders in which the variety of cookie matches the parameter coukieVar. The master order may contain zero or more cookie orders with the same variety as cookievar. The method returns the total number of boxes removed from the master order. For example, consider the following code segment. Masterorder goodies = new Masterorder(); goodies.addOrder(new CookieOrder("Chocolate Chip", 1)); goodies.addOrder (new Cookieorder("Shortbread", 5)) ; goodies.addOrder (new Cookieorder("Macaroon", 2)) ; goodies.addOrder(new CookieOrder("Chocolate Chip", 3)); After the code segment has executed, the contents of the master order are as shown in the following table. The method call goodies.removeVariety ("Chocolate Chip") returns 4 because there were two Chocolate Chip cookie orders totaling 4 boxes. The master order is modified as shown below. The method call goodies. removeVariety ("Brownie") returns 0 and does not change the master order. Complete method removeVariety below. / Removes all cookie orders from the master order that have the same variety of * cookie as cookievar and returns the total number of boxes that were removed. * Aparam cookievar the variety of cookies to remove from the master order * ereturn the total number of boxes of cookievar in the cookie orders removed */ public int removeVariety (String cookievar)

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

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions

Question

My opinions/suggestions are valued.

Answered: 1 week ago