Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in Java Inheritance hierarchy watercraft

in Java Inheritance hierarchy watercraft <====sailboat and canoe a. (Refer to inheritance hierarchy 8-1.) Write the code for the WaterCraft class. This class should include instance variables named id (int), type (string), and length (double) that can only be accessed by the class. Code a single constructor that assigns default values to the instance variables, and code get and set methods for the instance variables. b. Write the code for the Sailboat class. This class should extend the WaterCraft class by adding an instance variable named sails (int) and get and set methods for this variable. Its constructor should initialize the instance variables defined by the WaterCraft class by calling the constructor of that class, and it should assign a default value to the sails instance variable. c. (Refer to inheritance hierarchy 8-1.) Code a public method for the WaterCraft class that overrides the toString method of the Object class. This method should return a string that contains the id, type, and length variables in this format: ID: 1234 Type: Sailboat Length: 19' d. Assume that you have created a Sailboat object named s and assigned it to a WaterCraft object named w. Write a statement that will print the type of the WaterCraft object to the console. e. Assume that you have created a WaterCraft object named w. Write an if clause that will check if the object is a Sailboat object, using the easiest technique available. f. Assume that the WaterCraft class has been defined as abstract with an abstract method name getDisplayText() that accepts no parameter and returns a string: i. public abstract String getDisplayText();

Write the code for a method in the Sailboat class that overrides the abstract getDisplayText method in the WaterCraft class. The value thats returned by this method should include the length and type fields from the WaterCraft class and the sails field from the Sailboat class formatted like this: 19.0' Sailboat with 3 sails

put the corrisponding answers with the letter ie A is .......

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

in Java Inheritance hierarchy watercraft

Answered: 1 week ago