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
bcf24370
Commit
bcf24370
authored
2 years ago
by
HSoreide
Browse files
Options
Downloads
Patches
Plain Diff
Write first draft of Ingredient class
parent
7652ca5e
No related branches found
No related tags found
1 merge request
!7
Create food and recipe classes with tests
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/ntnu/idatt1002/demo/data/recipes/Ingredient.java
+60
-0
60 additions, 0 deletions
.../java/no/ntnu/idatt1002/demo/data/recipes/Ingredient.java
with
60 additions
and
0 deletions
src/main/java/no/ntnu/idatt1002/demo/data/recipes/Ingredient.java
0 → 100644
+
60
−
0
View file @
bcf24370
package
no.ntnu.idatt1002.demo.data.recipes
;
public
class
Ingredient
{
private
FoodItem
foodType
;
private
double
amount
;
private
MeasuringUnit
unit
;
public
Ingredient
(
FoodItem
ingredient
,
double
amount
,
MeasuringUnit
unit
)
{
if
(
ingredient
==
null
|
amount
<
0.0f
|
unit
==
null
)
{
throw
new
IllegalArgumentException
(
"The ingredient must have a type, amount and measuring unit."
);
}
this
.
foodType
=
ingredient
;
this
.
amount
=
amount
;
this
.
unit
=
unit
;
}
public
FoodItem
getFoodType
()
{
return
foodType
;
}
public
void
setFoodType
(
FoodItem
foodType
)
{
if
(
foodType
==
null
)
{
throw
new
IllegalArgumentException
(
"The food type must be set to a valid value of FoodItem."
);
}
this
.
foodType
=
foodType
;
}
public
double
getAmount
()
{
return
amount
;
}
public
void
setAmount
(
double
amount
)
{
if
(
amount
<
0.0f
)
{
throw
new
IllegalArgumentException
(
"The amount of an ingredient cannot be zero or negative."
);
}
this
.
amount
=
amount
;
}
public
MeasuringUnit
getUnit
()
{
return
unit
;
}
public
void
setUnit
(
MeasuringUnit
unit
)
{
if
(
unit
==
null
)
{
throw
new
IllegalArgumentException
(
"The food's measuring unit must be set to a valid value of MeasuringUnit."
);
}
this
.
unit
=
unit
;
}
@Override
public
String
toString
()
{
return
"Ingredient{"
+
"foodType="
+
foodType
.
label
+
", amount="
+
amount
+
", unit="
+
unit
.
label
+
'}'
;
}
}
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