Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
idatt1002_2023_9
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Kluge Svendsrud
idatt1002_2023_9
Commits
0702c60c
Commit
0702c60c
authored
2 years ago
by
HSoreide
Browse files
Options
Downloads
Patches
Plain Diff
Add JavaDoc to the Item class.
parent
cf3d4643
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Hs item class
Pipeline
#202067
passed
2 years ago
Stage: build
Stage: test
Stage: package
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/ntnu/idatt1002/demo/data/Item.java
+49
-3
49 additions, 3 deletions
src/main/java/no/ntnu/idatt1002/demo/data/Item.java
with
49 additions
and
3 deletions
src/main/java/no/ntnu/idatt1002/demo/data/Item.java
+
49
−
3
View file @
0702c60c
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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment