I'm reviewing for the AP Computer Science A exam, and the code I wrote is a little different from the answer. Do you think you could check if each outputs the same result?
Objective: To remove a Cookie Order of a specific type from the CookieOrder ArrayList order, and return the number of boxes removed. Please assume that all methods work as suggested.
Answer:
public int removeVariety(String cookieVar) { int boxesRemoved = 0; for (int i = orders.size() - 1; i >= 0; i--) { if (cookieVar.equals(orders.get(i).getVariety())) boxesRemoved += orders.remove(i).getNumBoxes(); }
return boxesRemoved; }
What I put:
public int removeVariety(String cookieVar) { String cookieType = cookieVar; int totalRemoved = 0; for(CookieOrder boxes : this.order) { String type = boxes.getVariety(); int totalBoxesCookieOrder = boxes.getNumBoxes(); if(type.equals(cookieType)) { totalRemoved += totalBoxesCookieOrder; this.order.remove(boxes); } } return totalRemoved; }
Would this still work? Alternatively, if you would like to grade me, here's the scoring rubric (question 1, part B). I appreciate the help; the test is tomorrow and I'm super nervous.