Create the following two classes.
1. Boat – this class contains:
i. a private instance variable name of type String which is initialised to “unknown”
ii. a private instance variable, boatClass, of type String initialised to “unknown”
iii. a private instance variable, regNum, of type int initialised to -1
iv. a method called toString that has no formal parameters and returns the boat’s name, class
and registration number, as a String, in the following format:
Boat name, Class = boatClass, Registration # = KA regNum
where the words in italics should be replaced with the values of the corresponding instance
COMP2741/COMP8741 Practical 2, Checkpoints 9-16
Flinders University Page 2 of 7 2020
2. BoatMaker – refactor the class that contains the main method created when the project was
created (possibly called Practical2) by changing its name to BoatMaker (right-click on its name
and select “Refactor->Rename” or Shift-F6). Modify the main method so that it:
i. Prints the message “Starting boat application”
ii. Defines a variable called myBoat of type Boat, initialised to a new Boat object.
iii. Prints the value of myBoat (causing the toString method to be called on the object
referred to by myBoat).
Run the project. The following output should be prod
Go to Source
Author: Rajwinder Chahal