Bug 316 - Adding beverage with negative price
Summary: Adding beverage with negative price
Status: RESOLVED FIXED
Alias: None
Product: Group20
Classification: Unclassified
Component: Beverage (show other bugs)
Version: unspecified
Hardware: PC Linux
: Low normal
Assignee: awkakavou2-c
URL:
Depends on:
Blocks:
 
Reported: 2019-11-26 12:39 HKT by Anders
Modified: 2019-12-08 17:26 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anders 2019-11-26 12:39:10 HKT
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;
}
Comment 1 awkakavou2-c 2019-12-08 17:26:39 HKT
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;
	}