7.4 KiB
Objective: Here, you'll have the opportunity to showcase your mastery of Java syntax, arrays, String class, OOP concepts, and class relationships. Embrace the challenge and let your understanding shine!
Estimated Time: 3 hours
Task: Mr. John Hammond has asked for some basic software to help manage his theme park. (He says he will "spare no expense", but we'll see.) Version 1.0 of the software will create Java objects to represent the park itself and the dinosaurs within. Yes, dinosaurs. With this software, park operators will be able to plan each of the different types of dinosaurs the park contains as it develops and opens.
Instructions
Begin by creating a new Java project in Eclipse, named according to the lab guidelines - project name should be "abc123-lab1", where abc123 is your UTSA ID.
Create the following new Java classes in the default package: (Use these names exactly!)
Java Class | Comment |
---|---|
Park.java | |
Dinosaur.java | This will be an interface |
Theropod.java | This will be an abstract class, 1 of 3 types of Dinosaur |
Sauropod.java | This will be an abstract class, 1 of 3 types of Dinosaur |
Stegosaur.java | This will be an abstract class, 1 of 3 types of Dinosaur |
Tyrannosaurus.java | This will be a class, 1 of 2 types of Theropod |
Velociraptor.java | This will be a class, 1 of 2 types of Theropod |
Apatosaurus.java | This will be a class, 1 of 2 types of Sauropod |
Brachiosaurus.java | This will be a class, 1 of 2 types of Sauropod |
Stegosaurus.java | This will be a class, 1 of 1 types of Stegosaur |
Note that we will have a few relationships between these classes. A Park contains ('has-a') Dinosaurs. There are 3 types of Dinosaurs: Theropods, Sauropods, and Stegosaurs. Velociraptor and Tyrannosaurus are types of Theropod. Apatosaurus and Brachiosaurus are types of Sauropod. Stegosaurus is a type of Stegosaur.
Place the given Lab1.java
class in the default package within your project. Lab1.java
has a main method and will be the class to run our application. Follow the remaining instructions for each class in this lab in order to get your code to compile - do not change the given class. Note that this code will not compile until you have completed the requirements of this lab. There will be syntax errors until all dependencies (classes and methods) are implemented. Once your code compiles, you will be able to examine the output of your program. The output of your program must match the format of the sample below. This sample is the result of running the Lab1.java
class with the given main method.
Welcome to Jurassic Park!
- - - - - - - - - - - - -
* Theropod: Velociraptor named Blue (carnivore)
* Theropod: Velociraptor named Delta (carnivore)
* Theropod: Velociraptor named Echo (carnivore)
* Theropod: Tyrannosaurus named Rex (carnivore)
* Sauropod: Apatosaurus named Littlefoot (not carnivore)
* Sauropod: Brachiosaurus named Bob (not carnivore)
* Stegosaur: Stegosaurus named Spike (not carnivore)
More Details
Park.java
This class will represent a Park object, which we will define as having:
- A name, represented as a String (e.g: Jurassic Park)
- A max capacity of dinosaurs, represented as an int (e.g. in
Lab1.java
, the max capacity is set to $10$) - Dinosaurs, stored as an array of Dinosaur objects (e.g.
Dinosaur[]
) - A constructor that initializes all instance variables and any other constructors as needed
- An
addDino(...)
method, which takes as a parameter aDinosaur
object and returns nothing - A
toString()
method, which calls upon thetoString()
method inDinosaur.java
to return as a String all needed information (see the output above) - Getters and setters for all variables
Dinosaur.java
This class will represent a Dinosaur, which we will define as an interface. This interface should declare the following methods (for the subclasses to implement):
- A method
isVegetarian()
, which takes no parameters and returns aboolean
for whether or not the dinosaur is a vegetarian (if not, they eat meat!) - A
getName()
which takes no parameters and returns a String of the dinosaur’s name (e.g. "Echo") - A
getType()
method which takes no parameters and returns a String of the dinosaur’s type (e.g. "Theropod - Velociraptor") - A
toString()
method which returns a String representation of the dinosaur (see output above)
Theropod.java, Sauropod.java, Stegosaur.java
These classes will be abstract classes, representing the types of dinosaurs in our park. Each class should implement the Dinosaur interface and each should have:
- A name, represented as a String (i.e.: Rex)
- Whether or not the dino is a vegetarian - very important! This will be represented as a
boolean
(e.g.false
, for Rex, our tyrannosaurus) - A constructor that initializes all instance variables, and any other constructors as needed
- A
toString()
method which returns a String representation of the dinosaur by calling upon "getter" methods. - A
getType()
method, fulfilling the requirements of the super class. - An abstract method
getSubType()
which takes no parameters and returns a sub type of dinosaur (e.g. "Velociraptor"). This method should be called by thegetType()
method.
Velociraptor.java, Tyrannosaurus.java, Apatosaurus.java, Brachiosaurus.java, Stegosaurus.java
These classes these will be very short classes in terms of amount of code. The classes will represent the specific types of dinosaurs which can be added to the park. Each class should extend its respective abstract class (see above for which classes should extend which abstract classes). In addition, they should have:
- A constructor that initializes all instance variables, and any other constructors as needed
- A
getType()
method which fulfills the requirements of the super class.
Additional Notes
- Follow Java code style including the capitalization of your zip file, project name, and class names, and variables. (Recall that names of Java variables and methods should be in camel case)
- This lab is meant to review regular arrays in Java, no other data structure may be used to store the objects required. (No ArrayLists are permitted, for example).
- All classes should have Javadoc comments.
- The grader will test your code by modifying the main method in Lab1.java to add different dinos to a different park. If coded according to the requirements of this lab, your submission will output the correct result. However, if you "hard code" any portion of the lab (except Lab1.java, which again, you should not modify) your submission will fail this test case.)
Submitting Your Lab:
-
When you have finished programming, create a zip file of the project and submit it on Canvas
- right-click on your project in Eclipse
- Click "Export"
- Under "General" choose "Archive File"
- Ensure your project name is selected in the top left listing of projects (only the project you need to submit). Ensure all required files are included.
- Under "To archive file", select a place to save your file and name your zip file (for labs, follow the abc123-labX.zip convention)
- Upload only the zip file to Canvas (here)
If you have any questions, feel free to reach out!