| Summary: | Creating beverage with empty string | ||
|---|---|---|---|
| Product: | Group20 | Reporter: | Anders <agmller2-c> |
| Component: | Beverage | Assignee: | awkakavou2-c |
| Status: | RESOLVED FIXED | ||
| Severity: | major | CC: | awkakavou2-c |
| Priority: | --- | ||
| Version: | 1.0 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
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;
|
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; }