diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Item.java b/src/main/java/no/ntnu/idatt1002/demo/data/Item.java index e33fc21158e912f03f63c17c3110c7478a079f23..c9c65c9304e9572e8aaa011e0df181bc8075e1a0 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Item.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Item.java @@ -1,11 +1,24 @@ package no.ntnu.idatt1002.demo.data; +/** + * The Item class represents an object or service purchased in real life. The item belongs to a category and + * has a price and description. The description may be left blank, but the Item must belong to a category and must + * have a price. + * @author HanneSofie + * + */ public class Item { - private Category category; private String description = ""; private float price; + /** + * The constructor of a new Item object takes in a Category and a price. The category is a value of the + * Category enum class, whereas the price is provided as a float. If category or price is left blank, an + * IllegalArgumentException is thrown. + * @param category The category the Item belongs to. + * @param price The price of an Item as a float. + */ public Item (Category category, float price){ if(category == null || price <= 1.0f) { throw new IllegalArgumentException("The item must have a category and a price."); @@ -15,33 +28,66 @@ public class Item { } } + /** + * The constructor instantiates a new Item object with a category, a description and a price as arguments. It + * overloads the first constructor to set the category and price and then sets the description of the item. + * If either 0category or price is left blank, an IllegalArgumentException is thrown. + * @param category The category the Item belongs to. + * @param description A description of the item as a String. + * @param price The price of the item as a float. + */ public Item (Category category, String description, float price){ this(category, price); this.description=description; } - - + /** + * The method returns the category to which the Item belongs as a value of the Category enum class. + * @return The category the Item belongs to as a value of the Category enum class. + */ public Category getCategory() { return category; } + /** + * The method sets the category of an item to a value of the Category enum class. + * @param category The category to which the Item should belong. + */ public void setCategory(Category category) { + if(category == null) { + throw new IllegalArgumentException("The category must be valid."); + } this.category = category; } + /** + * The method returns the description of the given Item object as a String. + * @return The description of the Item as a String. + */ public String getDescription() { return description; } + /** + * The method sets the description of the Item object equal to the passed String. The String may be empty. + * @param description The new description of the Item object as a String. + */ public void setDescription(String description) { this.description = description; } + /** + * The method returns the price of the given Item object as a float. + * @return The price of the Item as a float. + */ public float getPrice() { return price; } + /** + * The method changes the price of the given Item to the passed price as a float. + * @param price The new price of the Item as a float. + */ public void setPrice(float price) { this.price = price; }