Directions: SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. . Notes Assume that the classes listed in the Quick Reference found in the Appendix have been imported where appropriate Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods may not receive full credit. 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 public /** 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. 3 The Masterorder class maintains a list of the cookies to be purchased. The declaration of the Masterorder class is shown below. public 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 theorder the cookie order to add to the master order */ public void addorder (Cookieorder theorder) Torders.add(theOrder); } /** @return the sum of the mumber of boxes of all of the cookie orders public int get TotalBoxes ( { /* 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. aparam 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. } 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. 3 (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 mumber of boxes of all of the cookie orders */ public int get TotalBoxes ()