Need this answered within an hour, Programming Language is JAVA. Output is provi
ID: 3883265 • Letter: N
Question
Need this answered within an hour, Programming Language is JAVA. Output is provided, but it shouldn't just print out the output. It should prompt me, and then I enter what's in the Output. Ship.java is now provided.
Purpose: To review inheritance in java by defining a superclass and two subclasses, instantiating objects of those classes, and calling methods of the instantiated objects Instructions: Modify class Ship to meet the revised requirements described in the following UML Class Diagram Ship Attributes private name: String private year: int private builder: String Name of the ship Year of build Builder company Operations cconstructor Ship): ShipExplanation / Answer
class Ship
{
private String name;
private int year;
private String builder;
Ship()
{
name="";
builder="";
}
Ship(String n,int y,String b)
{
name=n;
year=y;
builder=b;
}
final public void setName(String aName)
{ name = aName; }
final public void setYear(int aYear)
{
year = aYear;
}
final public void setBuilder(String aBuilder)
{
builder=aBuilder;
}
final public String getName(){
return name;
}
final public int getYear(){
return year;
}
final public String getBuilder(){
return builder;
}
public String toString()
{
return "Name: "+name+" Year: "+year+" Builder: "+builder;
}
}
class Tanker extends Ship
{
private String type;
private int vol_capacity;
Tanker()
{
super();
}
Tanker(String name,int year,String builder,String type,int vol_capacity)
{
super(name,year,builder);
this.type=type;
this.vol_capacity=vol_capacity;
}
final public void setType(String aType)
{
type=aType;
}
final public void setVol_capacity(int aVol_capacity)
{
vol_capacity=aVol_capacity;
}
final public String getType()
{
return type;
}
final public int getVol_capacity()
{
return vol_capacity;
}
public String toString()
{
return super.getName()+" "+type+" "+vol_capacity+" "+super.getBuilder()+" "+super.getYear();
}
}
class Cruise extends Ship
{
private String type;
private int pas_capacity;
Cruise()
{
super();
}
Cruise(String name,int year,String builder,String type,int pas_capacity)
{
super(name,year,builder);
this.type=type;
this.pas_capacity=pas_capacity;
}
final public void setType(String aType)
{
type=aType;
}
final public void setpas_capacity(int apas_capacity)
{
pas_capacity=apas_capacity;
}
final public String getType()
{
return type;
}
final public int getpas_capacity()
{
return pas_capacity;
}
public String toString()
{
return super.getName()+" "+type+" "+pas_capacity+" "+super.getBuilder()+" "+super.getYear();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.