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
5410072d
Commit
5410072d
authored
May 04, 2021
by
Eky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zoo app
parents
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
440 additions
and
0 deletions
+440
-0
.classpath
zooApplication/.classpath
+15
-0
.gitignore
zooApplication/.gitignore
+1
-0
.project
zooApplication/.project
+17
-0
module-info.java
zooApplication/src/module-info.java
+6
-0
Animal.java
zooApplication/src/zooApplication/Animal.java
+58
-0
Avian.java
zooApplication/src/zooApplication/Avian.java
+29
-0
Main.java
zooApplication/src/zooApplication/Main.java
+9
-0
Mammal.java
zooApplication/src/zooApplication/Mammal.java
+33
-0
Mythic.java
zooApplication/src/zooApplication/Mythic.java
+18
-0
Piscine.java
zooApplication/src/zooApplication/Piscine.java
+29
-0
Reptile.java
zooApplication/src/zooApplication/Reptile.java
+26
-0
UnitTest.java
zooApplication/src/zooApplication/UnitTest.java
+92
-0
Zoo.java
zooApplication/src/zooApplication/Zoo.java
+107
-0
No files found.
zooApplication/.classpath
0 → 100644
View file @
5410072d
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER"
>
<attributes>
<attribute
name=
"module"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.junit.JUNIT_CONTAINER/5"
>
<attributes>
<attribute
name=
"module"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
zooApplication/.gitignore
0 → 100644
View file @
5410072d
/bin/
zooApplication/.project
0 → 100644
View file @
5410072d
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
zooApplication
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
</natures>
</projectDescription>
zooApplication/src/module-info.java
0 → 100644
View file @
5410072d
module
zooApplication
{
exports
zooApplication
;
requires
junit
;
}
\ No newline at end of file
zooApplication/src/zooApplication/Animal.java
0 → 100644
View file @
5410072d
package
zooApplication
;
import
java.util.ArrayList
;
public
class
Animal
{
public
String
species
;
public
String
habitat
;
public
String
food
;
public
ArrayList
<
String
>
specialTraits
=
new
ArrayList
<
String
>();
//Basic traits: species name, habitat and food
public
Animal
(
String
species
,
String
habitat
,
String
food
)
{
this
.
species
=
species
;
this
.
habitat
=
habitat
;
this
.
food
=
food
;
}
//Add custom trait
public
void
addTrait
(
String
input
)
{
this
.
specialTraits
.
add
(
input
);
return
;
}
//Remove specific trait
public
void
removeTrait
(
String
input
)
{
if
(
specialTraits
.
size
()>
0
)
{
for
(
int
i
=
0
;
i
<
specialTraits
.
size
();
i
++)
{
if
(
specialTraits
.
get
(
i
).
equals
(
input
))
{
specialTraits
.
remove
(
i
);
}
}
}
return
;
}
//Find trait - returns true if trait exists for this animal
public
boolean
findTrait
(
String
input
)
{
if
(
specialTraits
.
size
()>
0
)
{
for
(
int
i
=
0
;
i
<
specialTraits
.
size
();
i
++)
{
if
(
specialTraits
.
get
(
i
).
equals
(
input
))
{
return
true
;
}
}
}
return
false
;
}
}
zooApplication/src/zooApplication/Avian.java
0 → 100644
View file @
5410072d
package
zooApplication
;
public
class
Avian
extends
Animal
{
//Basic - assumes bird can fly
public
Avian
(
String
species
,
String
habitat
,
String
food
)
{
super
(
species
,
habitat
,
food
);
setFlight
(
true
);
}
//Option to declare flightless
public
Avian
(
String
species
,
String
habitat
,
String
food
,
boolean
flight
)
{
super
(
species
,
habitat
,
food
);
setFlight
(
flight
);
}
private
void
setFlight
(
boolean
flight
)
{
String
canFly
=
"Can Fly"
;
if
(
flight
==
false
)
{
canFly
=
"Flightless"
;}
addTrait
(
canFly
);
return
;
}
}
zooApplication/src/zooApplication/Main.java
0 → 100644
View file @
5410072d
package
zooApplication
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
org
.
junit
.
runner
.
JUnitCore
.
main
(
"zooApplication.UnitTest"
);
}
}
zooApplication/src/zooApplication/Mammal.java
0 → 100644
View file @
5410072d
package
zooApplication
;
import
java.util.ArrayList
;
public
class
Mammal
extends
Animal
{
//Basic - assumes mammal is not a large predator
public
Mammal
(
String
species
,
String
habitat
,
String
food
)
{
super
(
species
,
habitat
,
food
);
}
//Option to declare mammal is a large predator
public
Mammal
(
String
species
,
String
habitat
,
String
food
,
boolean
predator
)
{
super
(
species
,
habitat
,
food
);
setPredator
(
predator
);
}
//Option to declare a mammal that might have unusual traits (e.g. it can fly)
public
Mammal
(
String
species
,
String
habitat
,
String
food
,
ArrayList
<
String
>
oddTraits
)
{
super
(
species
,
habitat
,
food
);
this
.
specialTraits
=
oddTraits
;
}
private
void
setPredator
(
boolean
predator
)
{
if
(
predator
==
true
)
{
addTrait
(
"Large predator"
);}
return
;
}
}
zooApplication/src/zooApplication/Mythic.java
0 → 100644
View file @
5410072d
package
zooApplication
;
import
java.util.ArrayList
;
public
class
Mythic
extends
Animal
{
//Just for fun
public
Mythic
(
String
species
,
String
habitat
,
String
food
)
{
super
(
species
,
habitat
,
food
);
}
public
Mythic
(
String
species
,
String
habitat
,
String
food
,
ArrayList
<
String
>
mythicTraits
)
{
super
(
species
,
habitat
,
food
);
this
.
specialTraits
=
mythicTraits
;
}
}
zooApplication/src/zooApplication/Piscine.java
0 → 100644
View file @
5410072d
package
zooApplication
;
public
class
Piscine
extends
Animal
{
//Basic - assumes fish is salt water
public
Piscine
(
String
species
,
String
habitat
,
String
food
)
{
super
(
species
,
habitat
,
food
);
setSaline
(
true
);
}
//Option to declare fresh water
public
Piscine
(
String
species
,
String
habitat
,
String
food
,
boolean
saline
)
{
super
(
species
,
habitat
,
food
);
setSaline
(
saline
);
}
private
void
setSaline
(
boolean
saline
)
{
String
water
=
"Salt water"
;
if
(
saline
==
false
)
{
water
=
"Fresh water"
;}
addTrait
(
water
);
return
;
}
}
zooApplication/src/zooApplication/Reptile.java
0 → 100644
View file @
5410072d
package
zooApplication
;
public
class
Reptile
extends
Animal
{
//Basic - assumes reptile non-venomous
public
Reptile
(
String
species
,
String
habitat
,
String
food
)
{
super
(
species
,
habitat
,
food
);
}
//Option to declare venom
public
Reptile
(
String
species
,
String
habitat
,
String
food
,
boolean
venom
)
{
super
(
species
,
habitat
,
food
);
setVenomous
(
venom
);
}
private
void
setVenomous
(
boolean
input
)
{
String
venom
=
"Venomous"
;
if
(
input
==
true
)
{
addTrait
(
venom
);}
return
;
}
}
zooApplication/src/zooApplication/UnitTest.java
0 → 100644
View file @
5410072d
package
zooApplication
;
import
org.junit.*
;
//import org.junit.runner.*;
import
static
org
.
junit
.
Assert
.*;
import
java.util.ArrayList
;
public
class
UnitTest
{
@SuppressWarnings
(
"serial"
)
public
ArrayList
<
String
>
batSpec
=
new
ArrayList
<
String
>()
{{
add
(
"Can Fly"
);}};
@SuppressWarnings
(
"serial"
)
public
ArrayList
<
String
>
platSpec
=
new
ArrayList
<
String
>()
{{
add
(
"Egg Laying"
);
add
(
"Venomous"
);}};
@SuppressWarnings
(
"serial"
)
public
ArrayList
<
String
>
dragSpec
=
new
ArrayList
<
String
>()
{{
add
(
"Can Fly"
);
add
(
"Breathes Fire"
);
add
(
"Large Predator"
);
}};
public
Animal
wolf
=
new
Mammal
(
"Wolf"
,
"Mountain"
,
"Meat"
);
public
Animal
tiger
=
new
Mammal
(
"Tiger"
,
"Jungle"
,
"Meat"
,
true
);
public
Animal
fruitBat
=
new
Mammal
(
"Fruit Bat"
,
"Jungle"
,
"Fruit"
,
batSpec
);
public
Animal
platypus
=
new
Mammal
(
"Platypus"
,
"Riverlands"
,
"Invertebrates"
,
platSpec
);
public
Animal
eagle
=
new
Avian
(
"Eagle"
,
"Mountain"
,
"Meat"
);
public
Animal
emu
=
new
Avian
(
"Emu"
,
"Desert"
,
"Vegetation"
,
false
);
public
Animal
shark
=
new
Piscine
(
"Shark"
,
"Water"
,
"Meat"
);
public
Animal
carp
=
new
Piscine
(
"Carp"
,
"Water"
,
"Vegetation"
,
false
);
public
Animal
cobra
=
new
Reptile
(
"Cobra"
,
"Desert"
,
"Meat"
,
true
);
public
Animal
crocodile
=
new
Reptile
(
"Crocodile"
,
"Riverlands"
,
"Meat"
)
{{
addTrait
(
"Large Predator"
);}};
public
Animal
dragon
=
new
Mythic
(
"Dragon"
,
"Volcano"
,
"Maidens"
,
dragSpec
);
@SuppressWarnings
(
"serial"
)
public
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
Zoo
ysjZoo
=
new
Zoo
(
zooAnimals
);
@Test
public
void
testBasic
()
{
assertEquals
(
true
,
ysjZoo
.
containsAnimal
(
wolf
));
System
.
out
.
println
(
"\nTest: Display Single Animal\n"
);
ysjZoo
.
displayDetails
(
wolf
);
}
@Test
public
void
testDisplayAll
()
{
assertTrue
(
ysjZoo
.
zooList
.
size
()>
0
);
System
.
out
.
println
(
"\nTest: Display All Animals\n"
);
ysjZoo
.
displayAll
(
ysjZoo
.
zooList
);
}
@Test
public
void
testAnimalTypeList
()
{
System
.
out
.
println
(
"\nTest: Display all Mammals\n"
);
ArrayList
<
Animal
>
test
=
ysjZoo
.
typeList
(
"Mammal"
);
assertTrue
(
test
.
size
()>
0
);
ysjZoo
.
displayAll
(
test
);
}
@Test
public
void
foodList
()
{
System
.
out
.
println
(
"\nTest: Print food list for Mammals"
);
ArrayList
<
Animal
>
test
=
ysjZoo
.
typeList
(
"Mammal"
);
assertTrue
(
test
.
size
()>
0
);
System
.
out
.
println
(
"\n"
+
ysjZoo
.
foodList
(
test
));
}
@Test
public
void
enviroList
()
{
System
.
out
.
println
(
"\nTest: Print animals of Jungle habitat\n"
);
ArrayList
<
Animal
>
test
=
ysjZoo
.
enviroList
(
ysjZoo
.
zooList
,
"Jungle"
);
assertTrue
(
test
.
size
()>
0
);
ysjZoo
.
displayAll
(
test
);
}
}
zooApplication/src/zooApplication/Zoo.java
0 → 100644
View file @
5410072d
package
zooApplication
;
import
java.util.ArrayList
;
public
class
Zoo
{
public
ArrayList
<
Animal
>
zooList
=
new
ArrayList
<
Animal
>();
//Create object using a pre-existing list
public
Zoo
(
ArrayList
<
Animal
>
zooList
)
{
this
.
zooList
=
zooList
;
}
//Create object with empty list for adding to later
public
Zoo
(){}
//Add animal
public
void
addToZoo
(
Animal
animal
)
{
zooList
.
add
(
animal
);
}
//Remove animal
public
void
removeFromZoo
(
Animal
animal
)
{
zooList
.
remove
(
animal
);
}
//Returns true if list contains animal
public
boolean
containsAnimal
(
Animal
animal
)
{
if
(
zooList
.
contains
(
animal
))
{
return
true
;
}
return
false
;
}
//Display details of specific animal in list
public
void
displayDetails
(
Animal
animal
)
{
if
(
containsAnimal
(
animal
))
{
System
.
out
.
println
(
"Name: "
+
animal
.
species
+
"\nHabitat: "
+
animal
.
habitat
+
"\nFood: "
+
animal
.
food
);
if
(
animal
.
specialTraits
.
size
()>
0
)
{
System
.
out
.
println
(
"Special Traits: "
+
animal
.
specialTraits
);
}
}
}
//Displays all animals in list
public
void
displayAll
(
ArrayList
<
Animal
>
input
)
{
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++)
{
displayDetails
(
input
.
get
(
i
));
System
.
out
.
println
(
""
);
}
}
//generates list of animal of specific type
public
ArrayList
<
Animal
>
typeList
(
String
animal
)
{
ArrayList
<
Animal
>
output
=
new
ArrayList
<
Animal
>();
for
(
int
i
=
0
;
i
<
zooList
.
size
();
i
++)
{
if
(
zooList
.
get
(
i
).
getClass
().
getSimpleName
().
equals
(
animal
))
{
output
.
add
(
zooList
.
get
(
i
));
}
}
return
output
;
}
//Generates list of foods that a list of animals needs
public
ArrayList
<
String
>
foodList
(
ArrayList
<
Animal
>
input
)
{
ArrayList
<
String
>
output
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++)
{
output
.
add
(
input
.
get
(
i
).
food
);
}
return
output
;
}
//Checks which animals in a list belong to a specific habitat
public
ArrayList
<
Animal
>
enviroList
(
ArrayList
<
Animal
>
input
,
String
habitat
)
{
ArrayList
<
Animal
>
output
=
new
ArrayList
<
Animal
>();
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++)
{
if
(
input
.
get
(
i
).
habitat
.
equals
(
habitat
))
{
output
.
add
(
input
.
get
(
i
));
}
}
return
output
;
}
}
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