I'm new to programming and I'm trying to understand something. I have to write an additional subclass from the code below. Attributes I need to use are for a Rowboat, specifically type of material (wood, fiberglass, inflatable) and oartype (paddles, metal or wood). I then have to Include accessor methods for the new class, a tellAboutSelf method that overrides then invokes the superclass method, and a tester program that tests the class.
Can anyone help me to sort this out? I'm lost! and don't know how to proceed
// Sailboat -- a subclass of abstract class Boat that
// overrides tellAboutSelf method in superclass
public class Sailboat extends Boat
{
// additional attributes beyond those inherited from Boat
private double MaterialType;
private int noSails;
private String motorType;
// constructor
public Sailboat(String aStateRegistrat ionNo, double aLength,
String aManufacturer, int aYear, double aKeelDepth,
int aNoSails, String aMotorType)
{
// invoke super class constructor
super(aStateReg istrationNo, aLength, aManufacturer, aYear);
// set subclass attribute values
setKeelDepth(aK eelDepth);
setNoSails(aNoS ails);
setMotorType(aM otorType);
}
// custom method overrides superclass method
public String tellAboutSelf()
{
// invokes four superclass get methods
String allDetails;
allDetails = "This is a sailboat "
+ getStateRegistr ationNo() + " " // invoke Boat method
+ getLength() + " " // invoke Boat method
+ getManufacturer () + " " // invoke Boat method
+ getYear() + " " // invoke Boat method
+ keelDepth + " "
+ noSails + " "
+ motorType;
return allDetails;
}
// set accessor methods
public void setKeelDepth(do uble aKeelDepth)
{ keelDepth = aKeelDepth; }
public void setNoSails(int aNoSails)
{ noSails = aNoSails; }
public void setMotorType(St ring aMotorType)
{ motorType = aMotorType; }
// get accessor methods
public double getKeelDepth()
{ return keelDepth; }
public int getNoSails()
{ return noSails; }
public String getMotorType()
{ return motorType; }
}
Can anyone help me to sort this out? I'm lost! and don't know how to proceed
// Sailboat -- a subclass of abstract class Boat that
// overrides tellAboutSelf method in superclass
public class Sailboat extends Boat
{
// additional attributes beyond those inherited from Boat
private double MaterialType;
private int noSails;
private String motorType;
// constructor
public Sailboat(String aStateRegistrat ionNo, double aLength,
String aManufacturer, int aYear, double aKeelDepth,
int aNoSails, String aMotorType)
{
// invoke super class constructor
super(aStateReg istrationNo, aLength, aManufacturer, aYear);
// set subclass attribute values
setKeelDepth(aK eelDepth);
setNoSails(aNoS ails);
setMotorType(aM otorType);
}
// custom method overrides superclass method
public String tellAboutSelf()
{
// invokes four superclass get methods
String allDetails;
allDetails = "This is a sailboat "
+ getStateRegistr ationNo() + " " // invoke Boat method
+ getLength() + " " // invoke Boat method
+ getManufacturer () + " " // invoke Boat method
+ getYear() + " " // invoke Boat method
+ keelDepth + " "
+ noSails + " "
+ motorType;
return allDetails;
}
// set accessor methods
public void setKeelDepth(do uble aKeelDepth)
{ keelDepth = aKeelDepth; }
public void setNoSails(int aNoSails)
{ noSails = aNoSails; }
public void setMotorType(St ring aMotorType)
{ motorType = aMotorType; }
// get accessor methods
public double getKeelDepth()
{ return keelDepth; }
public int getNoSails()
{ return noSails; }
public String getMotorType()
{ return motorType; }
}
Comment