This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
209 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public class CookieOrder { | ||
private String variety; | ||
private int numBoxes; | ||
|
||
/** Constructs a new CookieOrder object. */ | ||
public CookieOrder(String variety, int numBoxes) { | ||
this.variety = variety; | ||
this.numBoxes = numBoxes; | ||
} | ||
/** @return the variety of cookie being ordered | ||
*/ | ||
public String getVariety() { | ||
return variety; | ||
} | ||
/** @return the number of boxes being ordered | ||
*/ | ||
public int getNumBoxes() { | ||
return numBoxes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MasterOrder { | ||
/** The list of all cookie orders */ | ||
private List<CookieOrder> orders; | ||
/** Constructs a new MasterOrder object. */ | ||
public MasterOrder() { | ||
orders = new ArrayList<CookieOrder>(); | ||
} | ||
/** Adds theOrder to the master order. | ||
* @param theOrder 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() { | ||
int count = 0; | ||
for(CookieOrder c : orders) count += c.getNumBoxes(); | ||
return count; | ||
} | ||
|
||
/** 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) { | ||
int count = 0; | ||
|
||
for(int i = 0; i < orders.size(); i++) { | ||
if(orders.get(i).getVariety().equals(cookieVar)) { | ||
count += orders.get(i).getNumBoxes(); | ||
orders.remove(i); | ||
i--; | ||
} | ||
} | ||
|
||
return count; | ||
} | ||
|
||
public void printAllOrders() { | ||
for(CookieOrder each : orders) { | ||
System.out.println("\nVariety: " + each.getVariety()); | ||
System.out.println("NumBoxes: " + each.getNumBoxes()); | ||
} | ||
} | ||
// There may be instance variables, constructors, and methods that are not shown. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
public class Runner { | ||
public static void main(String args[]) { | ||
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)); | ||
|
||
goodies.printAllOrders(); | ||
|
||
System.out.println("\nTotal Orders: " + goodies.getTotalBoxes()); | ||
|
||
System.out.println("\nRemoving Macaroon: " + goodies.removeVariety("Macaroon")); | ||
|
||
goodies.printAllOrders(); | ||
|
||
System.out.println("\nTotal Orders: " + goodies.getTotalBoxes()); | ||
} | ||
} |