Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write this project Topics covered in this Lab: Inheritance and polymorphism. Use a Java IDE to complete this lab 1. Use the IDE assigned

Please write this project image text in transcribed
image text in transcribed
Topics covered in this Lab: Inheritance and polymorphism. Use a Java IDE to complete this lab 1. Use the IDE assigned by your lab instructor 2. Implement a superclass Ship that has two private instance variables: one of type int, (crew); and, one of type String. (name. Crew is the number of crew members, and name is the name of the ship You will receive no credit for this lab if the keyword 'protected'is used anywhere in your program. Make two sub-classes, Freighter and Liner, inherit from Ship 3. a. A Freighter has an instance variable called "capacity_" (type is double) A Liner has an instance variable called "passengers_" (type is int). 5 6. 7. b. The Ship class should have one constructor to initialize both instance variables using arguments from the constructor formal parameter list. Freighter and Liner should have only one constructor to initialize all instance variables including the inherited base class instance variables There are no default (or no-argument) constructors for this assignment. Each class should include mutator and accessor methods for each instance variable 8. a. Complete the mutator(set) methods and accessor get) methods for Ship class. b. The name of each mutator method should begin with the word set followed by the variable name setName, setCapacity, etc. Accessor method names start with the word get. The sub-classes will inherit some methods from the super-class. c 9. Write a method for each class named toString. The toString method will return a string with information about each instance field belonging to the class. The output string must include information about the inherited instance variable from the base class. 10. Modify the main program provided here to test your new program. 11. Demonstrate that the mutator methods for Crew, Passengers, and Capacity work correctly a. Input a ship of type Liner: i. Name-Loki ii. Crew-475, change to 420 iii. Passengers-1520, change to 1370 b. Input a ship of type Freighter: i. ii. iii. Name-Odin Crew-122, change to 127 Capacity= 12000, change to 12500 12. Submit your final program to the course instructor when you have completed the assignment 13. You will find source code to begin the lab on the next page. Be sure to complete the ship class with the required code changes. Look for the message: "Students fill in the code here 14. Your grade will be based on how well you grasp the concepts and how effectively you implement code re-use in the assignment. Your program must compile to receive credit for this assignment

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions

Question

How does selection differ from recruitment ?

Answered: 1 week ago