Question: ( 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
;
 (b) Given the class Ship that has a name, berth, and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!