Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task : Just a walk in the park! (I am trying to learn from this code and currently trying to build my own code, however

Task: Just a walk in the park! (I am trying to learn from this code and currently trying to build my own code, however I am stuck, PLEASE do not confuse this code for previously posted codes on chegg, I can promise you this is different than the others, I would really appreciate the help. please help and thank you

A 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.

Getting Started

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!)

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.

Lab1.java

Place the given Lab1.java class in the default package within your project.

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.

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.

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)

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 toString() method, which calls upon the toString() method in Dinosaur.java to return as a String all needed information (see the output above).

An addDino(..) method, which takes as a parameter a Dinosaur object and returns nothing.

Dinosaur.java

This class will represent a Dinosaur, which we will be an interface. This interface should declare the following methods (for the subclasses to implement):

A toString() method which returns a String representation of the dinosaur (see output above)

A method isVegetarian(), which takes no parameters and returns a boolean 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 dinosaurs name (e.g. Echo)

A getType() method which takes no parameters and returns a String of the dinosaurs type (e.g. Theropod: Velociraptor)

Theropod, Sauropod, & Stegosaur

These classes will be abstract classes, representing the types of dinosaurs in our park. This 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 which takes in a String name and a boolean for their vegetarian diet and initializes the fields.

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 the getType() method.

Velociraptor, Tyrannosaurus, Apatosaurus, Brachiosaurus, & Stegosaurus

These classes will represent the specific types of dinosaurs which can be added to the park. These should extend their respective abstract class (see Getting Started above for which classes should extend which abstract classes). In addition, they should have:

A constructor which takes in a String name and a boolean for their vegetarian diet and calls the constructor in the super class.

A getSubType() method which fulfills the requirements of the super class.

Note that these will be very short classes in terms of amount of code.

Please note for all classes:

Each class must have a constructor and getters & setters to accommodate all of its variables.

All classes must have a toString() method

As 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).

Lab1.java

public class Lab1 { public static void main( String[] args ) { // create a Park object Park jurassicPark = new Park( "Jurassic Park", 10 ); // All Parks contains Dinosaurs which come in different 3 types in our Jurassic Park: theropods, sauropods, & stegosaurs. // create dinosaurs to add to the park Theropod blue = new Velociraptor( "Blue", false ); // Velociraptors are a type of Theropod, which is a type of Dinosaur Theropod delta = new Velociraptor( "Delta", false ); // Velociraptors are a type of Theropod, which is a type of Dinosaur Theropod echo = new Velociraptor( "Echo", false ); // Velociraptors are a type of Theropod, which is a type of Dinosaur Theropod rex = new Tyrannosaurus( "Rex", false ); // Tyrannosaurus are a type of Theropod, which is a type of Dinosaur Sauropod littleFoot = new Apatosaurus( "Littlefoot", true ); // Apatosaurus are a type of Sauropod, which is a type of Dinosaur Sauropod bob = new Brachiosaurus( "Bob", true ); // Brachiosaurus are a type of Sauropod, which is a type of Dinosaur Stegosaur spike = new Stegosaurus( "Spike", true ); // Stegosaurus are a type of Stegosaur, which is a type of Dinosaur // add all dinos to the park jurassicPark.addDino( blue ); jurassicPark.addDino( delta ); jurassicPark.addDino( echo ); jurassicPark.addDino( rex ); jurassicPark.addDino( littleFoot ); jurassicPark.addDino( bob ); jurassicPark.addDino( spike ); // print the state of the park (see lab description) System.out.println( jurassicPark ); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 2.0 And Databases

Authors: John Kauffman, Bradley Millington

1st Edition

0471781347, 978-0471781349

More Books

Students also viewed these Databases questions

Question

Describe employee assistance programs.

Answered: 1 week ago

Question

Describe the importance of physical fitness programs.

Answered: 1 week ago

Question

Discuss the factors that set the stage for global HR practice.

Answered: 1 week ago