Question: need third problem use the information from problem1 and 2 Question1: You will write two separate classes. A Captain class that will allow us to

need third problem use the information from problem1 and 2

Question1:

You will write two separate classes. A Captain class that will allow us to create captains for boats and a CaptainTester class (partially complete) that we will use to test some of our Captain class methods. The Captain class will also be unit tested. The Captain class diagram is below; you cannot create more public methods than the ones on the diagram.

  • Captain(int,String,int,int): Creates a new captain given an age, name, years of experience and registry number on that order.
  • equals(Captain): This is the simplified version of equals (we are received a Captain object). Two captains are the same if they have the same name and the same registry number.
  • toString(): returns a String according to the example below (Captain's name is Christian Williams):

Christian Williams, age: 77 YoE: 50 Registry: 8974

Qustion2

A sailboat has a size in feet, a name, a model, and a Captain. New sailboats don't have a captain when they are created. Captains are assigned after they are created. How can you use the null reference to tell if there is or there isn't a captain assigned to a sailboat object?

  • ailboat(int,String,String): Creates a new sailboat given size (in feet), name, and model.
  • assignCaptain(Captain): assign a captain to a sailboat. If the sailboat already has a captain, the new captain must have more experience (in years of experience). If the new captain is not more experience the method should return false.
  • equals(Sailaboat): two sailboats are the same if they have the same name and the same captain
  • toString(): returns a String according to the example below:

No Captain Assigned

Relativity is a 25 feet C&C sailboat with no captain =/

Captain Assigned

Relativity is a 25 feet C&C sailboat; her captain is: Albert Einstein

Problem3:

In your main method, you will:

  1. Read the boat's name, model, and size. (Hint: after you read the size with nextInt(), call a nextLine() to remove the leftover ; otherwise you will have an inputMismatchException)
  2. Create a new sailboat object with the information you just read and print the object to the console.
  3. Now, read the captain's name, age, years of experience, and registry number.
  4. Create a new captain and assign it to the sailboat.
  5. Print the sailboat object again to the console.
  6. Get the captain from the sailboat object and print it to the console.

Example:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!