Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Programming02
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
james.young
Programming02
Commits
4094c5f6
Commit
4094c5f6
authored
May 16, 2022
by
james.young
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Programming02 GitLab Zoo Project
parent
8adc1517
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
312 additions
and
0 deletions
+312
-0
Programming02Zoo.java
Programming02Zoo.java
+312
-0
No files found.
Programming02Zoo.java
0 → 100644
View file @
4094c5f6
import
java.util.ArrayList
;
import
java.util.Scanner
;
import
java.util.*
;
import
java.util.regex.*
;
public
class
ArrayListProject
{
public
static
void
main
(
String
[]
args
)
{
//Build array lists for animal classifications
ArrayList
classificationList
=
new
ArrayList
();
classificationList
.
add
(
"Avians"
);
classificationList
.
add
(
"Mammals"
);
classificationList
.
add
(
"Reptiles"
);
classificationList
.
add
(
"Fish"
);
//System.out.println(classificationList);
//Build avian class
class
avian
{
String
name
;
static
String
diet
;
String
habitat
;
//Fix memory location print issue
@Override
public
String
toString
()
{
return
"Name: "
+
name
+
" |Diet: "
+
diet
+
" |Habitat: "
+
habitat
;
}
public
static
void
showDiet
()
{
System
.
out
.
println
(
avian
.
diet
);
}
}
avian
penguin
=
new
avian
();
penguin
.
name
=
"Penguin"
;
penguin
.
diet
=
"Omnivore"
;
penguin
.
habitat
=
"Arctic"
;
avian
roadrunner
=
new
avian
();
roadrunner
.
name
=
"Roadrunner"
;
roadrunner
.
diet
=
"Omnivore"
;
roadrunner
.
habitat
=
"Desert"
;
avian
parrot
=
new
avian
();
parrot
.
name
=
"Parrot"
;
parrot
.
diet
=
"Omnivore"
;
parrot
.
habitat
=
"Jungle"
;
//Build mammalia class
class
mammal
{
String
name
;
String
diet
;
String
habitat
;
//Fix memory location print issue
@Override
public
String
toString
()
{
return
"Name: "
+
name
+
" |Diet: "
+
diet
+
" |Habitat: "
+
habitat
;
}
}
mammal
polarbear
=
new
mammal
();
polarbear
.
name
=
"Polar Bear"
;
polarbear
.
diet
=
"Carnivore"
;
polarbear
.
habitat
=
"Arctic"
;
mammal
wilddog
=
new
mammal
();
wilddog
.
name
=
"African Wild Dog"
;
wilddog
.
diet
=
"Carnivore"
;
wilddog
.
habitat
=
"Desert"
;
mammal
jaguar
=
new
mammal
();
jaguar
.
name
=
"Jaguar"
;
jaguar
.
diet
=
"Carnivore"
;
jaguar
.
habitat
=
"Jungle"
;
//Build reptile class
class
reptile
{
String
name
;
String
diet
;
String
habitat
;
//Fix memory location print issue
@Override
public
String
toString
()
{
return
"Name: "
+
name
+
" |Diet: "
+
diet
+
" |Habitat: "
+
habitat
;
}
}
reptile
commonlizard
=
new
reptile
();
commonlizard
.
name
=
"Common Lizard"
;
commonlizard
.
diet
=
"Omnviore"
;
commonlizard
.
habitat
=
"Arctic"
;
reptile
hornedlizard
=
new
reptile
();
hornedlizard
.
name
=
"Horned Lizard"
;
hornedlizard
.
diet
=
"Omnivore"
;
hornedlizard
.
habitat
=
"Desert"
;
reptile
iguana
=
new
reptile
();
iguana
.
name
=
"Iguana"
;
iguana
.
diet
=
"Omnivore"
;
iguana
.
habitat
=
"Jungle"
;
//Build fish class
class
fish
{
String
name
;
String
diet
;
String
habitat
;
//Fix memory location print issue
@Override
public
String
toString
()
{
return
"Name: "
+
name
+
" |Diet: "
+
diet
+
" |Habitat: "
+
habitat
;
}
}
fish
pupfish
=
new
fish
();
pupfish
.
name
=
"Pupfish"
;
pupfish
.
diet
=
"Omnivore"
;
pupfish
.
habitat
=
"Desert"
;
fish
glshark
=
new
fish
();
glshark
.
name
=
"Greenland Shark"
;
glshark
.
diet
=
"Omnivore"
;
glshark
.
habitat
=
"Artic"
;
fish
arapaima
=
new
fish
();
arapaima
.
name
=
"Arapaima"
;
arapaima
.
diet
=
"Carnivore"
;
arapaima
.
habitat
=
"Jungle"
;
{
//Build avian arraylist
ArrayList
avianList
=
new
ArrayList
();
avianList
.
add
(
penguin
);
avianList
.
add
(
roadrunner
);
avianList
.
add
(
parrot
);
//stem.out.println(avianList);
//Build reptile arraylist
ArrayList
reptileList
=
new
ArrayList
();
reptileList
.
add
(
commonlizard
);
reptileList
.
add
(
hornedlizard
);
reptileList
.
add
(
iguana
);
//stem.out.println(reptileList);
//build mammal arraylist
ArrayList
mammaliaList
=
new
ArrayList
();
mammaliaList
.
add
(
wilddog
);
mammaliaList
.
add
(
jaguar
);
mammaliaList
.
add
(
polarbear
);
//build fish arraylist
ArrayList
fishList
=
new
ArrayList
();
fishList
.
add
(
pupfish
);
fishList
.
add
(
glshark
);
fishList
.
add
(
arapaima
);
//stem.out.println(fishList);
System
.
out
.
println
(
"Welcome to the Java Zoo!"
);
//Take in user input for first question
Scanner
scan
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Which classification would you like to view? (Avian, Mammalia, Fish, Reptile): "
);
String
q1response
=
scan
.
nextLine
();
// if statements for first question and appropriate response prints
if
(
q1response
.
toLowerCase
().
equals
(
"avian"
))
{
System
.
out
.
println
(
"The avians are: "
);
for
(
int
i
=
0
;
i
<
avianList
.
size
();
i
++)
{
System
.
out
.
println
(
avianList
.
get
(
i
)
+
" "
);
}
}
if
(
q1response
.
toLowerCase
().
equals
(
"reptile"
))
{
System
.
out
.
println
(
"The reptiles are: "
);
for
(
int
i
=
0
;
i
<
reptileList
.
size
();
i
++)
{
System
.
out
.
println
(
reptileList
.
get
(
i
)
+
" "
);
}
}
if
(
q1response
.
toLowerCase
().
equals
(
"mammalia"
))
{
System
.
out
.
println
(
"The mammals are: "
);
for
(
int
i
=
0
;
i
<
mammaliaList
.
size
();
i
++)
{
System
.
out
.
println
(
mammaliaList
.
get
(
i
)
+
" "
);
}
}
if
(
q1response
.
toLowerCase
().
equals
(
"fish"
))
{
System
.
out
.
println
(
"The fish are: "
);
for
(
int
i
=
0
;
i
<
fishList
.
size
();
i
++)
{
System
.
out
.
println
(
fishList
.
get
(
i
)
+
" "
);
}
}
Scanner
scan2
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Which diet would you like to view? (Omnivore or Carnivore): "
);
String
q2responsetest
=
scan
.
nextLine
();
//Thought there would be a better way of doing this rather than having to convert variables twice
String
q2responsetest2
=
q2responsetest
.
toLowerCase
();
String
q2response
=
q2responsetest2
.
substring
(
0
,
1
).
toUpperCase
()
+
q2responsetest2
.
substring
(
1
);
//Wow this is inefficient. Could iterate over a list perhaps?
if
(
q2response
.
equals
(
parrot
.
diet
))
{
System
.
out
.
println
(
parrot
.
name
+
" | "
+
parrot
.
diet
);
}
if
(
q2response
.
equals
(
penguin
.
diet
))
{
System
.
out
.
println
(
penguin
.
name
+
" | "
+
penguin
.
diet
);
}
if
(
q2response
.
equals
(
roadrunner
.
diet
))
{
System
.
out
.
println
(
roadrunner
.
name
+
" | "
+
roadrunner
.
diet
);
}
if
(
q2response
.
equals
(
polarbear
.
diet
))
{
System
.
out
.
println
(
polarbear
.
name
+
" | "
+
polarbear
.
diet
);
}
if
(
q2response
.
equals
(
wilddog
.
diet
))
{
System
.
out
.
println
(
wilddog
.
name
+
" | "
+
wilddog
.
diet
);
}
if
(
q2response
.
equals
(
jaguar
.
diet
))
{
System
.
out
.
println
(
jaguar
.
name
+
" | "
+
jaguar
.
diet
);
}
if
(
q2response
.
equals
(
hornedlizard
.
diet
))
{
System
.
out
.
println
(
hornedlizard
.
name
+
" | "
+
hornedlizard
.
diet
);
}
if
(
q2response
.
equals
(
commonlizard
.
diet
))
{
System
.
out
.
println
(
commonlizard
.
name
+
" | "
+
commonlizard
.
diet
);
}
if
(
q2response
.
equals
(
iguana
.
diet
))
{
System
.
out
.
println
(
iguana
.
name
+
" | "
+
iguana
.
diet
);
}
if
(
q2response
.
equals
(
glshark
.
diet
))
{
System
.
out
.
println
(
glshark
.
name
+
" | "
+
glshark
.
diet
);
}
if
(
q2response
.
equals
(
pupfish
.
diet
))
{
System
.
out
.
println
(
pupfish
.
name
+
" | "
+
pupfish
.
diet
);
}
if
(
q2response
.
equals
(
arapaima
.
diet
))
{
System
.
out
.
println
(
arapaima
.
name
+
" | "
+
arapaima
.
diet
);
}
Scanner
scan3
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Which habitat would you like to view? (Desert, Jungle, Arctic): "
);
String
qhabitattest
=
scan
.
nextLine
();
String
qhabitattest2
=
qhabitattest
.
toLowerCase
();
String
qhabitat
=
qhabitattest2
.
substring
(
0
,
1
).
toUpperCase
()
+
qhabitattest2
.
substring
(
1
);
//tring q2responsetest2 = q2responsetest.toLowerCase();
//tring q2response = q2responsetest2.substring(0,1).toUpperCase() + q2responsetest2.substring(1);
//Thought there would be a better way of doing this rather than having to convert variables twice
if
(
qhabitat
.
equals
(
parrot
.
habitat
))
{
System
.
out
.
println
(
parrot
.
name
+
" | "
+
parrot
.
habitat
);
}
if
(
qhabitat
.
equals
(
penguin
.
habitat
))
{
System
.
out
.
println
(
penguin
.
name
+
" | "
+
penguin
.
habitat
);
}
if
(
qhabitat
.
equals
(
roadrunner
.
habitat
)){
System
.
out
.
println
(
roadrunner
.
name
+
" | "
+
roadrunner
.
habitat
);
}
if
(
qhabitat
.
equals
(
polarbear
.
habitat
)){
System
.
out
.
println
(
polarbear
.
name
+
" | "
+
polarbear
.
habitat
);
}
if
(
qhabitat
.
equals
(
wilddog
.
habitat
)){
System
.
out
.
println
(
wilddog
.
name
+
" | "
+
wilddog
.
habitat
);
}
if
(
qhabitat
.
equals
(
jaguar
.
habitat
))
{
System
.
out
.
println
(
jaguar
.
name
+
" | "
+
jaguar
.
habitat
);
}
if
(
qhabitat
.
equals
(
hornedlizard
.
habitat
))
{
System
.
out
.
println
(
hornedlizard
.
name
+
" | "
+
hornedlizard
.
habitat
);
}
if
(
qhabitat
.
equals
(
commonlizard
.
habitat
))
{
System
.
out
.
println
(
commonlizard
.
name
+
" | "
+
commonlizard
.
habitat
);
}
if
(
qhabitat
.
equals
(
iguana
.
habitat
))
{
System
.
out
.
println
(
iguana
.
name
+
" | "
+
iguana
.
habitat
);
}
if
(
qhabitat
.
equals
(
glshark
.
habitat
))
{
System
.
out
.
println
(
glshark
.
name
+
" | "
+
glshark
.
habitat
);
}
if
(
qhabitat
.
equals
(
pupfish
.
habitat
))
{
System
.
out
.
println
(
pupfish
.
name
+
" | "
+
pupfish
.
habitat
);
}
if
(
qhabitat
.
equals
(
arapaima
.
habitat
))
{
System
.
out
.
println
(
arapaima
.
name
+
" | "
+
arapaima
.
habitat
);
}
}
}
}
// This is all the array lists and if statement stuff
//public static void stuff
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