Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java create 5 class files Dinosaur.java This file defines a Dinosaur object. Variables: The Dinosaur class must have these variables: - name - the name

java

create 5 class files

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Dinosaur.java This file defines a Dinosaur object. Variables: The Dinosaur class must have these variables: - name - the name of the dinosaur. This should be a String. It should be visible to subclasses of Dinosaur. An invalid value should default to "Barney". The value is invalid if name is an empty String, blank String, or null. This value cannot be changed once set and should be visible to any descendant classes. Think about what modifiers fit best for this! - height- a double representing the height of the dinosaur in feet. - width- a double representing the width of the dinosaur in feet. - weight-a double representing the weight in pounds. - totalenclosures - An int representing the total number of dinosaurs that have an enclosure at the park. Think about what reserved word you need to use for this variable. It should be visible to subclasses of Dinosaur. Constructor (s): - A constructor that takes in the name, height, width, and weight. - A constructor that takes in no parameters. name should be set to "Barney". height should be set to 15 , width should be 20 and weight should be set to 1000 . - A copy constructor that deep copies all necessary instance variables of the old object to the n object Methods : - enclosuresize() o Returns a double representing the area of the enclosure where the dinosaur is located o To calculate, multiply 10 times the width, followed by the height. - calculateFood() o Returns a double representing the amount of food in pounds needed to prepare for the dinosaur o To calculate, multiply weight times the width, followed by the height. - tostring() o Returns the String representation of the object. - Should return a String in the following format: " requires a square foot enclosure and name> is too expensive for the park!" o Otherwise, return a concatenation to tostring() with the following at the end of the concatenated string: " name> has been added to the park!" - Make sure to update all relevant variables in this method (i.e. increment the total number of dinosaurs in an enclosure when an enclosure is successfully built.) - Appropriate getters and setters for each of the instance and static variables. Pterodactyl.java This file defines a Pterodactyl object, which is a subclass of Dinosaur. Since they can fly, their enclosures need to account for the altitude they fly up to. Variables: In addition to the variables it inherits from its superclass, Pterodactyl should also have the following variables: - flightCeiling - a double representing the altitude the Pterodactyl can fly up to in the range [10,100] in feet. If an invalid value is entered, the variable should default to 50. Constructor (s) : - A constructor that takes in the name, height, width, weight, and flightCeiling. - A constructor that takes in the name, width, and defaults flightCeiling to 50, and all other variables to their default in Dinosaur. - A constructor that takes in name and defaults width to 12. All other variables should end up initialized to their corresponding defaults in Dinosaur and Pterodactyl. - A copy constructor that deep copies all instance variables of the old object to the new object. - HINT: Make sure to utilize constructor chaining whenever possible, and don't forget you can constructor chain to a parent class from a child class! Methods : - enclosureSize() o Returns a double representing the area of the enclosure where the dinosaur is located o To calculate, multiply four times the width, followed by the height. Then add flightCeiling to this value. o Override the enclosureSize() method from Dinosaur - toString() - Returns the String representation of the object. - Should return a String in the following format: " can fly feet into the air! requires a square foot enclosure and pounds of food. - Getters and setters for each of the instance variables. Pack.java This object will store details about the pack a dinosaur may belong to. Dinosaurs that belong to a pack will require more food and larger enclosures. Variables: - size - an int that represents the size of the pack in number. If an invalid value is entered, then the default value should be 4. An invalid value would be a negative number. - packName - a String that represents the name for this group of dinosaurs on the sign of the enclosure. An invalid value should default to "The Power Pack". The value is invalid if packName is attempted to be set to an empty String, blank String, or null. - NOTE: Both fields should be immutable, making the instances of this class effectively immutable. This means we do not need a copy constructor for this class. Constructor(s): - A constructor that takes in size and packName. Methods: - toString() o Return a String representation of the object in the given format: - Getters and setters when necessary. Velociraptor.java This file defines a Velociraptor object and should be a subclass of Dinosaur. The velociraptor runs a lot, which means they eat a greater amount of food compared to the regular dinosaur. Some velociraptors may belong to a pack in an enclosure or may hunt alone. Variables: In addition to the variables it inherits from its superclass, Velociraptor should also have the following variables: - speed - an int representing the speed of the velociraptor in miles per hour. An invalid value should be set to 30 . The value is invalid if it is negative. - pack - a Pack object representing whether the dinosaur belongs to a pack or not. A dinosaur who is not part of a pack will have this variable set to null. Constructor(s): - A constructor that takes in the name, height, width, weight, speed, and pack. - A constructor that takes in the name and height and defaults the speed to 30 , pack to null and all other variables to their default in Dinosaur. - A copy constructor that deep copies all mutable instance variables of the old object to the new object. Methods: The following methods should be public. - enclosureSize() o Returns a double representing the area of the enclosure where the dinosaur is located o If the dinosaur is not part of a pack, calculate the enclosure size by multiplying four times the width by the height. o If the dinosaur is part of a pack, calculate enclosure size by multiplying the size of the pack by the width by the height. o This method should override the enclosureSize() method from Dinosaur.java - calculateFood() o Returns a double representing the amount of food, in pounds, needed to prepare for the dinosaur's meal o To calculate, multiply weight times the speed by the height. - toString() o Returns the String representation of the object. o Should return a String in the following format: " requires a > square foot enclosure and > pounds of food." o If the dinosaur was part of a pack, return a string in the following format: " is a family of dinosaurs of size ! requires a s foot enclosure and > pounds of food." - Getters and setters for each of the instance variables. JurassicPark.java This Java file is a test driver Use this class's main method to test your code. - Create at least 2 Dinosaurs, 2 Pterodactyls, and 2 Velociraptors, and 1 Pack. - Use each of the copy constructors at least once. Try modifying the objects to see if you have deep copied properly. - Call the relevant buildEnclosure() methods on each Dinosaur and its children's objects and print the results. - Call toString() on all Velociraptors to print the results

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions