Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
object Orientertprogrammering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Markus Alexander Selander
object Orientertprogrammering
Commits
dbcbb6ac
Commit
dbcbb6ac
authored
1 year ago
by
Mathea Berg Vindsetmo
Browse files
Options
Downloads
Patches
Plain Diff
Farm
parent
cdacb3fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
foreksempel/src/main/java/of5_2/kode/Farm.java
+57
-0
57 additions, 0 deletions
foreksempel/src/main/java/of5_2/kode/Farm.java
with
57 additions
and
0 deletions
foreksempel/src/main/java/of5_2/kode/Farm.java
0 → 100644
+
57
−
0
View file @
dbcbb6ac
package
of5_2.kode
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
public
class
Farm
{
private
List
<
Animal
>
animals
=
new
ArrayList
<>();
public
void
addAnimal
(
Animal
animal
){
if
(
animals
.
contains
(
animal
)){
throw
new
IllegalArgumentException
(
"Animal already added"
);
}
animals
.
add
(
animal
);
}
public
List
<
Animal
>
getAnimals
(){
return
new
ArrayList
<>(
animals
);
}
public
int
numberOfAnimals
(){
return
this
.
animals
.
size
();
}
public
Animal
getAnimal
(
int
index
){
return
animals
.
get
(
index
);
}
public
static
void
main
(
String
[]
args
)
{
Dog
Ludo
=
new
Dog
(
"Ludo"
,
2
);
Chicken
Albert
=
new
Chicken
(
"Albert"
,
1
);
Dog
Ollie
=
new
Dog
(
"Ollie"
,
6
);
Dog
Buddy
=
new
Dog
(
"Buddy"
,
8
);
Chicken
Ringo
=
new
Chicken
(
"Ringo"
,
6
);
Chicken
Kjell
=
new
Chicken
(
"Kjell"
,
5
);
List
<
Animal
>
animals
=
new
ArrayList
<>(
List
.
of
(
Ludo
,
Albert
,
Ollie
,
Buddy
,
Ringo
,
Kjell
));
Farm
farm
=
new
Farm
();
farm
.
addAnimal
(
animals
.
get
(
0
));
farm
.
addAnimal
(
animals
.
get
(
1
));
farm
.
addAnimal
(
animals
.
get
(
2
));
farm
.
addAnimal
(
animals
.
get
(
3
));
farm
.
addAnimal
(
animals
.
get
(
4
));
farm
.
addAnimal
(
animals
.
get
(
5
));
}
}
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