Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( b ) Given the class Ship that has a name, berth, and speed write a class BattleShip, demonstrating BattleShip IS - A Ship relationship

(b) Given the class Ship that has a name, berth, and speed write a class BattleShip, demonstrating BattleShip IS-A Ship relationship using inheritance.
Class BattleShip requires an gunNo and helipadCount both of type int.
Class Battle Ship must have a constructor, getter and setter methods, and a toString method.
public class Ship {
private String name;
private String berth;
private int speed;
public Ship(String name, String berth, int speed){
this.name = name;
this. berth = berth;
this.speed = speed;
;
public String getName 0{
return name;
i
public void setName(String name){
this.name = name;
i
public String getBerth(0 :
return berth;
;
public void setBerth(String berth) :
this. berth = berth;
;
public int getSpeed 0 :
return speed;
Page 3 of 13
;
public void setSpeed(int speed){
this.speed = speed;
}
(a) Override
public String toString()
return "Ship "name="+ name +", berth =+ berth +", speed =+ speed +7?;
3
;
image text in transcribed

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

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

What is a job analysis?

Answered: 1 week ago

Question

What are the main provisions of the Fair Labor Standards Act?

Answered: 1 week ago