Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Ship{ // Declare the class instance fields as private here: // Write a constructor for the Ship class here. // Write mutator(set) methods

image text in transcribed

image text in transcribed

public class Ship{

// Declare the class instance fields as private here:

// Write a constructor for the Ship class here.

// Write mutator(set) methods for each instance field:

// Write accessor(get) methods for each instance field:

// Write the toString method to return the instance fields as a String. }

// Ship

please write it by JAVA, thanks for your help

Use the IDE assigned by your lab instructor 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 1. 2. 3. 4. a. A Freighter has an instance variable called "capacity "(type is double) b. A Liner has an instance variable called "passengers_" (type is int) The Ship class should have one constructor to initialize both instance variables using arguments from the constructor formal parameter list 5. 6. Freighter and Liner should have only one constructor to initialize all instance variables including the 7. 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. Complete the mutator(set) methods and accessor(get) methods for Ship class 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 a. b. 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 ii. Passengers 1520, change to 1370 b. Input a ship of type Freighter: i. Name-Odin ii. Crew-122, change to 127 ii. Capacity 12000, change to 12500 12. Submit your final program to the course instructor when you have completed the assignment 13. You wll 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

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions