Bug 305 - Creating beverage with empty string
Summary: Creating beverage with empty string
Status: RESOLVED FIXED
Alias: None
Product: Group20
Classification: Unclassified
Component: Beverage (show other bugs)
Version: 1.0
Hardware: PC Linux
: --- major
Assignee: awkakavou2-c
URL:
Depends on:
Blocks:
 
Reported: 2019-11-05 18:01 HKT by Anders
Modified: 2019-11-25 18:18 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-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;