Implement Boat, SallBoat and RowfBoat based upon the following diagram, in addit
ID: 3622506 • Letter: I
Question
Implement Boat, SallBoat and RowfBoat based upon the following diagram, in addition to the methods shown, implement a constructor for Boat so that length and names can be set at object creation, a constructor for sallboat that allows length, name, and numsalls to be set at object creation, an accessor and a mutator for numSalls in sallBoat and any necessary methods from superclass or interfaces. Use no instance variables that are not specified in the UML diagram makeltGo should print out a message appropriate for the type. Boat objects should be sortable by length.Explanation / Answer
/** * @author * */ import java.lang.String; public abstract class Boat implements Comparable { private double length = 0; private String name = ""; /** * @param l * @param n */ public Boat(double l, String n) { length = l; name = n; } /** * @param T */ public int compareTo(Boat T) { return((int)(getLength() - T.getLength())); } public double getLength() { return(length); } public String getName() { return(name); } public abstract void makeItGo(); } /** * @author * */ public interface Comparable { int compareTo(Boat T); } /** * @author * */ public class rowBoat extends Boat { /** * @param l * @param n */ public rowBoat(double l, String n) { super(l, n); // TODO Auto-generated constructor stub } /* (non-Javadoc) * @see Boat#makeItGo() */ @Override public void makeItGo() { System.out.println("Rowing"); } } /** * @author * */ public class SailBoat extends Boat { private int numSails = 0; /** * @param l * @param n */ public SailBoat(double l, String n, int s) { super(l, n); numSails = s; } /* (non-Javadoc) * @see Boat#makeItGo() */ @Override public void makeItGo() { System.out.println("Sailing"); } public int getNumSails() { return(numSails); } /** * @param s */ public void setNumSails(int s) { numSails = s; } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.