Bug 305

Summary: Creating beverage with empty string
Product: Group20 Reporter: Anders <agmller2-c>
Component: BeverageAssignee: awkakavou2-c
Status: RESOLVED FIXED    
Severity: major CC: awkakavou2-c
Priority: ---    
Version: 1.0   
Hardware: PC   
OS: Linux   

Description Anders 2019-11-05 18:01:47 HKT
I was able to create a beverage with just an empty string. I suggest the constructor should check if the string is empty upon object creating. The fix should be done in the code below:

public Beverage(String s, double d, int i) {
	this.name = s;
	this.price = d;
	this.id = i;
}
Comment 1 awkakavou2-c 2019-11-25 18:18:22 HKT
Hi, i fixed it by writing an exception which does not accept any input that is less than 1 character.
public class Beverage implements Item {
	private String name;
	private double price;
	private int id;
	
	public Beverage(String s, double d, int i) {
		if(s.length() < 1)
			throw new IllegalArgumentException("Empty name");
		else
			this.name = s;