Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java Assessment
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
reece.french
Java Assessment
Commits
51f9c672
Commit
51f9c672
authored
May 16, 2022
by
reece.french
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Attempt at ZooProject failed code
parent
61c38882
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
161 additions
and
0 deletions
+161
-0
Animal.java
Animal.java
+161
-0
No files found.
Animal.java
0 → 100644
View file @
51f9c672
import
java.util.ArrayList
;
public
class
Animal
{
static
String
name
;
static
String
diet
;
static
String
food
;
static
String
habitat
;
static
String
type
;
public
Animal
(
String
name
,
String
type
,
String
diet
,
String
food
,
String
habitat
)
{
Animal
.
name
=
name
;
Animal
.
type
=
type
;
Animal
.
diet
=
diet
;
Animal
.
food
=
food
;
Animal
.
habitat
=
habitat
;
}
public
String
display
()
{
return
"Name: "
+
name
+
"\n"
+
"Type: "
+
type
+
"\n"
+
"Diet: "
+
diet
+
"\n"
+
"Food: "
+
food
+
"\n"
+
"Habitat: "
+
habitat
;
}
public
String
group1
()
{
ArrayList
<
String
>
mammals
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
birds
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
fish
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
reptiles
=
new
ArrayList
<
String
>();
if
(
type
.
contains
(
"Mammal"
))
{
mammals
.
add
(
name
);
System
.
out
.
println
(
"Mammals list: "
+
mammals
);
}
else
{
System
.
out
.
println
();
}
if
(
type
.
contains
(
"Bird"
))
{
birds
.
add
(
name
);
System
.
out
.
println
(
"Birds list: "
+
birds
);
}
else
{
System
.
out
.
println
();
}
if
(
type
.
contains
(
"Fish"
))
{
fish
.
add
(
name
);
System
.
out
.
println
(
"Fish list: "
+
fish
);
}
else
{
System
.
out
.
println
();
}
if
(
type
.
contains
(
"Reptile"
))
{
reptiles
.
add
(
name
);
System
.
out
.
println
(
"Reptile list: "
+
reptiles
);
}
else
{
System
.
out
.
println
();
}
return
""
;
}
public
String
group2
()
{
ArrayList
<
String
>
carnivores
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
herbivores
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
omnivores
=
new
ArrayList
<
String
>();
if
(
diet
.
contains
(
"Carnivore"
))
{
carnivores
.
add
(
name
);
System
.
out
.
println
(
"Carnivore list: "
+
carnivores
);
}
else
{
System
.
out
.
println
();
}
if
(
diet
.
contains
(
"Herbivore"
))
{
herbivores
.
add
(
name
);
System
.
out
.
println
(
"Herbivore list: "
+
herbivores
);
}
else
{
System
.
out
.
println
();
}
if
(
diet
.
contains
(
"Omnivore"
))
{
omnivores
.
add
(
name
);
System
.
out
.
println
(
"Omnivore list: "
+
omnivores
);
}
else
{
System
.
out
.
println
();
}
return
""
;
}
public
String
group3
()
{
ArrayList
<
String
>
jungle
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
desert
=
new
ArrayList
<
String
>();
ArrayList
<
String
>
arctic
=
new
ArrayList
<
String
>();
if
(
habitat
.
contains
(
"Jungle"
))
{
jungle
.
add
(
name
);
System
.
out
.
println
(
"Animals in jungle habitat: "
+
jungle
);
}
else
{
System
.
out
.
println
();
}
if
(
habitat
.
contains
(
"Arctic"
))
{
arctic
.
add
(
name
);
System
.
out
.
println
(
"Animals in arctic habitat: "
+
arctic
);
}
else
{
System
.
out
.
println
();
}
if
(
habitat
.
contains
(
"Desert"
))
{
desert
.
add
(
name
);
System
.
out
.
println
(
"Animals in desert habitat: "
+
desert
);
}
else
{
System
.
out
.
println
();
}
return
""
;
}
public
static
void
main
(
String
[]
args
)
{
Animal
Animal1
=
new
Animal
(
"Tiger"
,
"Mammal"
,
"Carnivore"
,
"Meat"
,
"Jungle"
);
Animal
Animal2
=
new
Animal
(
"Bear"
,
"Mammal"
,
"Omnivore"
,
"Meat/plants"
,
"Forest"
);
Animal
Animal3
=
new
Animal
(
"Shark"
,
"Fish"
,
"Carnivore"
,
"Meat"
,
"Aquatic"
);
Animal
Animal4
=
new
Animal
(
"Iguana"
,
"Reptile"
,
"Herbivore"
,
"Plants"
,
"Forest"
);
Animal
Animal5
=
new
Animal
(
"Cheetah"
,
"Mammal"
,
"Carnivore"
,
"Meat"
,
"Desert"
);
System
.
out
.
println
(
Animal1
.
group1
());
System
.
out
.
println
(
Animal2
.
group1
());
System
.
out
.
println
(
Animal3
.
group1
());
System
.
out
.
println
(
Animal4
.
group1
());
System
.
out
.
println
(
Animal5
.
group1
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment