Instructions If you think my puns are bad, you should check out boat names as you walk past any dock! Today, you are going to be working with some boat names that are docked at a local marina. Today's POD.java has been created for you. You are going to create a Sailboat class in Sailboat.java. POD.java makes use of the Sailboat class. You are going to write the Sailboat class in Sailboatjava You've been given an empty Sallboat class. Inside this empty class, you will create the fields, the constructor and write the toString() method to be used for output. The main method in POD.java has been written for you. It reads in boat names, instantiates the class Sailboat (multiple times), and then prints out the result using the toString() method. Details Input Create the following class fields: - string boatName: the name of the sailboat - counter counter: static value to be used within the class to keep track of how many dock spaces have already been used so far. - integer dockSpace: number of the dock space the sailboat will be assigned. When a new sailboat is brought into the marina (i.e. constructed), it will be assigned a dock space one greater than the one before it. Processing Create a Sailboat constructor: - The following input parameter is expected: - string: the name of the boat to be docked - Assign this boat name to the appropriate field - Increment the counter · Assign the new counter to the ȘdockSpaces field Create the toString() method for output (as below) Output The output is achieved by using the toString() method in the Sallboat.Java object class. It should be of the format BOAT-NAME is at dock space DOCK-SPACE Sample Input/output: Sample input (PoD.Java) Yeah, buoy! What's up dock?
Java.
Starter Code for PoD class:
import java.util.Scanner;
public class PoD {
public static void main( String [] args ) {
Scanner in = new Scanner(System.in);
final int MARINA_SIZE= 10;
String[] boatNames = new String[MARINA_SIZE];
Sailboat[] boats = new Sailboat[MARINA_SIZE];
int i = 0;
while (in.hasNextLine())
{
boatNames[i] = in.nextLine();
boats[i] = new Sailboat(boatNames[i]);
System.out.println(boats[i]);
i++;
}
System.out.print("END OF OUTPUT");
}
}
Other code for class Sailboat:
public class Sailboat
{
// PLEASE START YOUR CODE HERE
// *********************************************************
// *********************************************************
// PLEASE END YOUR CODE HERE
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images