Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit

Permalink
Classwork from February 15, 2019
Browse files Browse the repository at this point in the history
  • Loading branch information
neilbalch committed Feb 20, 2019
1 parent aef129f commit b7bb17b
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 142 deletions.
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

244 changes: 102 additions & 142 deletions .idea/workspace.xml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Q3/02152019/02152019.iml
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>
20 changes: 20 additions & 0 deletions Q3/02152019/CookieOrder.java
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;
}
}
51 changes: 51 additions & 0 deletions Q3/02152019/MasterOrder.java
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.
}
19 changes: 19 additions & 0 deletions Q3/02152019/Runner.java
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());
}
}

0 comments on commit b7bb17b

Please sign in to comment.