Within the Beverage.java class, it is possible to add a beverage with a negative price, which obviously should throw an error. A check should be made upon creation of a beverage object to make sure, that the price is actually positive. I believe the check could be made in the section below from beverage.java. public Beverage(String s, double d, int i) { this.name = s; this.price = d; this.id = i; }
Hello, I added the fix to your problem, i believe now it should be fine. An error will be thrown if someone tries to add a beverage with a negative price, cheers, public class Beverage implements Item { private String name; private double price; private int id; public Beverage(String s, double d, int i) { //not relevant if(d < 0) throw new IllegalArgumentException("Negative price"); else this.price = d; this.id = i; }