Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

APCS A-ArrayList (Cookies) An organization raises money by selling boxes of cookies. A cookie order specifies the variety of cookie and the number of boxes

image text in transcribedimage text in transcribed

APCS A-ArrayList (Cookies) 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 */ } /** @return the variety of cookie being ordered public String getVariety() { /* implementation not shown */ } /** @return 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. @param the order the cookie order to add to the master order public void addorder (CookieOrder theOrder) { orders.add(theOrder); } /** @return 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. @param cookieVar the variety of cookies to remove from the master order * @return 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. /** @return the sum of the number of boxes of all of the cookie orders public int getTotalBoxes () (6) The removeVariety method updates the master order by removing all of the cookie orders in which the variety of cookie matches the parameter cookievar. 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. "Chocolate Chip" 1 "Shortbread" 5 "Macaroon" 2 "Chocolate Chip" 3 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. "Shortbread" 5 "Macaroon" 2 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. * @param cookieVar the variety of cookies to remove from the master order @return 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

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago