Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added NegativeSalesException, updated ShopTest #2

Merged
merged 1 commit into from
Jan 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EconomicSimulationProject-Java-</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions Iteration_3/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/customerPackage/
/inventoryPackage/
/resources/
/simulationPackage/
Binary file modified Iteration_3/bin/inventoryPackage/Shop.class
Binary file not shown.
Binary file modified Iteration_3/bin/inventoryPackage/ShopTest.class
Binary file not shown.
17 changes: 17 additions & 0 deletions Iteration_3/src/inventoryPackage/NegativeSalesException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package inventoryPackage;

/**
*
* @author patrickmcdermott
*
* Thrown to indicate that the increment was negative.
*
*/
public class NegativeSalesException extends IllegalArgumentException {


private static final long serialVersionUID = 1L;



}
9 changes: 7 additions & 2 deletions Iteration_3/src/inventoryPackage/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ public class Shop {
//Sets selection of items to empty
public void clearSelection() {selectedItems = new ArrayList<>();}

//Increments sales by given amount
/**
* Increments this shop object's sales
* by the value of the argument passed.
* Throws new NegativeSalesException if the argument passed is less than 0.
* @param increment value as a double
*/
public void incrementSales(double increment) {
if (increment < 0) throw new IllegalArgumentException();
if (increment < 0) throw new NegativeSalesException();
else this.sales += increment;
}

Expand Down
2 changes: 1 addition & 1 deletion Iteration_3/src/inventoryPackage/ShopTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void createShop() {
}


@Test (expected = Exception.class)
@Test (expected = NegativeSalesException.class)
public void testIncrementSales() {
shop.incrementSales(-10.00);
}
Expand Down