Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with writing a JAVA code Please do not copy from other experts and approach all question Dinosaur. java This file defines a

Please help me with writing a JAVA code

Please do not copy from other experts and approach all question

image text in transcribed

image 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 nu1l. 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 1600 . - A copy constructor that deep copies all necessary instance variables of the old object to the new object Methods : - enclosuresize() o Returns a double representing the area of the enclosure where the dinosaur is located - To calculate, multiply 10 times the width, followed by the height. - calculateFood() - Returns a double representing the amount of food in pounds needed to prepare for the dinosaur - To calculate, multiply weight times the width, followed by the height. - tostring() - Returns the String representation of the object. - Should return a String in the following format: " requires a pounds of food." - buildEnclosure() - Each dinosaur has a given area for its enclosure and a set of amount of food. If the calculations from calculateFood() and enclosuresize() exceeds that limit, then we cannot build the enclosure. o If enclosuresize() exceeds 6000 or calculatefood() exceeds 80000 , return a concatenation to tostring() with the following at the end of the concatenated string: " 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!" o 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. - HIMT: 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() - 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. o Should return a String in the following format: "name> can fly flightCeiling> feet into the air! square foot enclosure and requires a > square foot enclosure and pounds of food." 0 If the dinosaur was part of a pack, return a string in the following format: " is a family of dinosaurs of size ! requires a > square foot enclosure and pounds of food." - Getters and setters for each of the instance variables. JurassicPark.java This Java fie 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 buidenclosure() methods on each Dinosaur and its chidren's objects and print the resuls. - 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_2

Step: 3

blur-text-image_3

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

2. Discuss the steps in preparing a manager to go overseas.

Answered: 1 week ago