Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
Stewart_Eccleston_COM4005M_zooApplication
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
stewart.eccleston
Stewart_Eccleston_COM4005M_zooApplication
Commits
318c409c
Commit
318c409c
authored
May 04, 2021
by
Eky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new update
parent
5410072d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
10 deletions
+129
-10
Main.java
zooApplication/src/zooApplication/Main.java
+103
-1
UnitTest.java
zooApplication/src/zooApplication/UnitTest.java
+2
-2
Zoo.java
zooApplication/src/zooApplication/Zoo.java
+24
-7
No files found.
zooApplication/src/zooApplication/Main.java
View file @
318c409c
package
zooApplication
;
package
zooApplication
;
import
java.util.ArrayList
;
import
java.util.Scanner
;
public
class
Main
public
class
Main
{
{
@SuppressWarnings
(
"serial"
)
public
static
ArrayList
<
String
>
batSpec
=
new
ArrayList
<
String
>()
{{
add
(
"Can Fly"
);}};
@SuppressWarnings
(
"serial"
)
public
static
ArrayList
<
String
>
platSpec
=
new
ArrayList
<
String
>()
{{
add
(
"Egg Laying"
);
add
(
"Venomous"
);}};
@SuppressWarnings
(
"serial"
)
public
static
ArrayList
<
String
>
dragSpec
=
new
ArrayList
<
String
>()
{{
add
(
"Can Fly"
);
add
(
"Breathes Fire"
);
add
(
"Large Predator"
);
}};
public
static
Animal
wolf
=
new
Mammal
(
"Wolf"
,
"Mountain"
,
"Meat"
);
public
static
Animal
tiger
=
new
Mammal
(
"Tiger"
,
"Jungle"
,
"Meat"
,
true
);
public
static
Animal
fruitBat
=
new
Mammal
(
"Fruit Bat"
,
"Jungle"
,
"Fruit"
,
batSpec
);
public
static
Animal
platypus
=
new
Mammal
(
"Platypus"
,
"Riverlands"
,
"Invertebrates"
,
platSpec
);
public
static
Animal
eagle
=
new
Avian
(
"Eagle"
,
"Mountain"
,
"Meat"
);
public
static
Animal
emu
=
new
Avian
(
"Emu"
,
"Desert"
,
"Vegetation"
,
false
);
public
static
Animal
shark
=
new
Piscine
(
"Shark"
,
"Water"
,
"Meat"
);
public
static
Animal
carp
=
new
Piscine
(
"Carp"
,
"Water"
,
"Vegetation"
,
false
);
public
static
Animal
cobra
=
new
Reptile
(
"Cobra"
,
"Desert"
,
"Meat"
,
true
);
public
static
Animal
crocodile
=
new
Reptile
(
"Crocodile"
,
"Riverlands"
,
"Meat"
)
{{
addTrait
(
"Large Predator"
);}};
public
static
Animal
dragon
=
new
Mythic
(
"Dragon"
,
"Volcano"
,
"Maidens"
,
dragSpec
);
@SuppressWarnings
(
"serial"
)
public
static
ArrayList
<
Animal
>
zooAnimals
=
new
ArrayList
<
Animal
>()
{{
add
(
wolf
);
add
(
tiger
);
add
(
fruitBat
);
add
(
platypus
);
add
(
eagle
);
add
(
emu
);
add
(
shark
);
add
(
carp
);
add
(
cobra
);
add
(
crocodile
);
add
(
dragon
);
}};
public
static
Zoo
ysjZoo
=
new
Zoo
(
zooAnimals
);
public
static
void
main
(
String
[]
args
)
public
static
void
main
(
String
[]
args
)
{
{
org
.
junit
.
runner
.
JUnitCore
.
main
(
"zooApplication.UnitTest"
);
//org.junit.runner.JUnitCore.main("zooApplication.UnitTest");
boolean
end
=
false
;
Scanner
scan
=
new
Scanner
(
System
.
in
);
String
input
;
String
name
;
System
.
out
.
println
(
"Welcome to the Zoo!\n"
);
do
{
System
.
out
.
println
(
"\nPlease choose an option:"
);
System
.
out
.
println
(
"1: Search for animal and display details."
);
System
.
out
.
println
(
"2: Display all animals in zoo."
);
System
.
out
.
println
(
"3: Display list of animals of specific type."
);
System
.
out
.
println
(
"4: Display food required for list of animals of certain type."
);
System
.
out
.
println
(
"5: Display all animals from a certain environment."
);
System
.
out
.
println
(
"x: Exit."
);
input
=
scan
.
next
();
if
(
input
.
equals
(
"1"
))
{
System
.
out
.
println
(
"\n\nPlease enter name of animal (capital letter for name):"
);
name
=
scan
.
next
();
ysjZoo
.
displayDetails
(
name
);
}
else
if
(
input
.
equals
(
"2"
))
{
ysjZoo
.
displayAll
(
ysjZoo
.
zooList
);
}
else
if
(
input
.
equals
(
"3"
))
{
System
.
out
.
println
(
"\n\nPlease enter name of type (capital letter for name):"
);
name
=
scan
.
next
();
ArrayList
<
Animal
>
types
=
ysjZoo
.
typeList
(
name
);
ysjZoo
.
displayAll
(
types
);
}
else
if
(
input
.
equals
(
"4"
))
{
System
.
out
.
println
(
"\n\nPlease enter name of type (capital letter for name):"
);
name
=
scan
.
next
();
ArrayList
<
Animal
>
types
=
ysjZoo
.
typeList
(
name
);
System
.
out
.
println
(
ysjZoo
.
foodList
(
types
));
}
else
if
(
input
.
equals
(
"5"
))
{
System
.
out
.
println
(
"\n\nPlease enter name of environment (capital letter for name):"
);
name
=
scan
.
next
();
ArrayList
<
Animal
>
enviros
=
ysjZoo
.
enviroList
(
zooAnimals
,
name
);
ysjZoo
.
displayAll
(
enviros
);
}
else
if
(
input
.
equals
(
"x"
))
{
end
=
true
;
}
}
while
(
end
==
false
);
}
}
}
}
zooApplication/src/zooApplication/UnitTest.java
View file @
318c409c
...
@@ -50,9 +50,9 @@ public class UnitTest
...
@@ -50,9 +50,9 @@ public class UnitTest
@Test
@Test
public
void
testBasic
()
public
void
testBasic
()
{
{
assertEquals
(
true
,
ysjZoo
.
containsAnimal
(
wolf
));
assertEquals
(
true
,
ysjZoo
.
containsAnimal
(
"wolf"
));
System
.
out
.
println
(
"\nTest: Display Single Animal\n"
);
System
.
out
.
println
(
"\nTest: Display Single Animal\n"
);
ysjZoo
.
displayDetails
(
wolf
);
ysjZoo
.
displayDetails
(
"wolf"
);
}
}
@Test
@Test
...
...
zooApplication/src/zooApplication/Zoo.java
View file @
318c409c
...
@@ -28,26 +28,43 @@ public class Zoo
...
@@ -28,26 +28,43 @@ public class Zoo
}
}
//Returns true if list contains animal
//Returns true if list contains animal
public
boolean
containsAnimal
(
Animal
animal
)
public
boolean
containsAnimal
(
String
animal
)
{
{
if
(
zooList
.
contains
(
animal
)
)
for
(
int
i
=
0
;
i
<
zooList
.
size
();
i
++
)
{
{
return
true
;
if
(
zooList
.
get
(
i
).
species
.
equals
(
animal
))
{
return
true
;
}
}
}
return
false
;
return
false
;
}
}
//Display details of specific animal in list
public
int
animalIndex
(
String
animal
)
public
void
displayDetails
(
Animal
animal
)
{
{
if
(
containsAnimal
(
animal
))
for
(
int
i
=
0
;
i
<
zooList
.
size
();
i
++)
{
if
(
zooList
.
get
(
i
).
species
.
equals
(
animal
))
{
return
i
;
}
}
return
0
;
}
//Display details of specific animal in list
public
void
displayDetails
(
String
input
)
{
if
(
containsAnimal
(
input
))
{
{
Animal
animal
=
zooList
.
get
(
animalIndex
(
input
));
System
.
out
.
println
(
"Name: "
+
animal
.
species
+
"\nHabitat: "
+
animal
.
habitat
+
"\nFood: "
+
animal
.
food
);
System
.
out
.
println
(
"Name: "
+
animal
.
species
+
"\nHabitat: "
+
animal
.
habitat
+
"\nFood: "
+
animal
.
food
);
if
(
animal
.
specialTraits
.
size
()>
0
)
if
(
animal
.
specialTraits
.
size
()>
0
)
{
{
System
.
out
.
println
(
"Special Traits: "
+
animal
.
specialTraits
);
System
.
out
.
println
(
"Special Traits: "
+
animal
.
specialTraits
);
}
}
}
}
else
{
System
.
out
.
println
(
"This animal is not in the zoo!"
);}
}
}
//Displays all animals in list
//Displays all animals in list
...
@@ -55,7 +72,7 @@ public class Zoo
...
@@ -55,7 +72,7 @@ public class Zoo
{
{
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++)
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++)
{
{
displayDetails
(
input
.
get
(
i
));
displayDetails
(
input
.
get
(
i
)
.
species
);
System
.
out
.
println
(
""
);
System
.
out
.
println
(
""
);
}
}
}
}
...
...
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