Question: Step 2: Create a Sailboat class using the Boat class as the super class and having the following attributes and methods: Attributes numSails Method Sailboat

Step 2: Create a Sailboat class using the Boat class as the super class and having the following attributes and methods: Attributes numSails Method Sailboat Sailboat Data type An int that holds the number of sailboat sails Description The Boat class default constructor that sets the numSails to 1 Constructor with 3 parameters - a String for the boat color, an int for the boat length and an int for the number of sails. The color and the length are passed to the Boat class 2-parameter constructor while number of sails is initialized to using the setNumSails mutator. A mutator that tests the input parameter to ensure it is in the range of 1 to 4 inclusive. If so, it sets numSails and returns true. For all other values, numSails is not set and a false is returned. Returns the int value of numSails Calculates the price of the Sailboat as follows: length * 1000 + numSails * 2000 Returns a string using String.format: super.toString() + "Number of Sails = " + numSails + " Price = " + calcPrice set NumSails getNumSails calcPrice toString Step 3: Create a test class, Test Sailboat, that creates an object of the Sailboat class and prints the output of the toString method. Test the mutators for errors and print appropriate error messages. Lab11 Inheritance-bash - 107x23 Janeway: Lab11 Inheritance jims java TestSailboat Sailboat: Color = red Length = 25 Number Sails = 2 Cost = $ 29,800.ee Changing Sailboat's color to purple. Error: Boats can only be white, red, blue, or yellow. Changing Sailboat's length to 55. Error: Sail Boats can only be between 20 and so feet, inclusively. Janeway: Lab11 Inheritance jim Step 2: Create a Sailboat class using the Boat class as the super class and having the following attributes and methods: Attributes numSails Method Sailboat Sailboat Data type An int that holds the number of sailboat sails Description The Boat class default constructor that sets the numSails to 1 Constructor with 3 parameters - a String for the boat color, an int for the boat length and an int for the number of sails. The color and the length are passed to the Boat class 2-parameter constructor while number of sails is initialized to using the setNumSails mutator. A mutator that tests the input parameter to ensure it is in the range of 1 to 4 inclusive. If so, it sets numSails and returns true. For all other values, numSails is not set and a false is returned. Returns the int value of numSails Calculates the price of the Sailboat as follows: length * 1000 + numSails * 2000 Returns a string using String.format: super.toString() + "Number of Sails = " + numSails + " Price = " + calcPrice set NumSails getNumSails calcPrice toString Step 3: Create a test class, Test Sailboat, that creates an object of the Sailboat class and prints the output of the toString method. Test the mutators for errors and print appropriate error messages. Lab11 Inheritance-bash - 107x23 Janeway: Lab11 Inheritance jims java TestSailboat Sailboat: Color = red Length = 25 Number Sails = 2 Cost = $ 29,800.ee Changing Sailboat's color to purple. Error: Boats can only be white, red, blue, or yellow. Changing Sailboat's length to 55. Error: Sail Boats can only be between 20 and so feet, inclusively. Janeway: Lab11 Inheritance jim
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
