Skip to content
Snippets Groups Projects
Commit 0702c60c authored by HSoreide's avatar HSoreide
Browse files

Add JavaDoc to the Item class.

parent cf3d4643
No related branches found
No related tags found
1 merge request!1Hs item class
Pipeline #202067 passed
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment