Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need to write code that will test the junit test in the photo. I was givin these hints : Harbor Before you continue,

Hello, I need to write code that will test the junit test in the photo.
I was givin these hints :
Harbor
Before you continue, go ahead and visit the style guide from the module. Comment your Boat class per the required style.
The Harbor class will be a class that has-many Boat objects. This means you should be using a data structure (Arrays!).
Constructor
A Harbor is created with a parameter that corresponds to the number of spots for Boats. Hint: The size of your array.
getBoatAt
This method should return the boat at the given index, null if that spot is empty.
parkBoatAt
This method will set the position in the array, but if there is a Boat at the given position, return that object. Otherwise, it returns null.
getInventory
Return a copy of the inventory. Hint: This is not just a getter/accessor for the one-dimensional array of Boat objects! Make sure to write your own code to create the copy; do not use the Arrays class or a clone method.
For the remainder of the classes, see if you can figure out the logic based on the tester.
Hints: You will have to override the toString method multiple times in this programming assignment. Make sure you include required white spaces!
@Test
void testHarbor()
{
// A harbor has many boats
Boat boat1= new Boat ("BMC", Color. GREEN);
Boat boat2= new Boat ("BMX", Color. RED );
Boat boat3= new Boat ("UXB", Color. YELLOW);
Harbor stock = new Harbor (5);
assertEquals (null, stock.getBoatAt (0));
assertEquals (null, stock.getBoatAt (1));
assertEquals (null, stock.getBoatAt (2));
assertEquals (null, stock.getBoatAt (3));
assertEquals (null, stock.getBoatAt (4));
// Hint: parkBoatAt is not just an accessor, and not just a mutator
assertEquals (null, stock.parkBoatAt (boat1,3));
Boat retrievedBoat = stock.parkBoatAt (boat2,3);
assertEquals (boat1, retrievedBoat);
retrievedBoat = stock.parkBoatAt (boat3,3);
assertEquals (boat2, retrievedBoat);
Boat[] inventory = stock.getInventory ();
assertArrayEquals (new Boat []{null, null, null, boat3, null}, inventory);
stock.parkBoatAt (boat2,1);
// The inventory is a carbon copy list of boats that is handed out to interested parties.
assertArrayEquals (new Boat []{null, null, null, boat3, null}, inventory); // This is correct!
assertArrayEquals (new Boat []{null, boat2, null, boat3, null}, stock.getInventory());
}
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Readings In Database Systems

Authors: Michael Stonebraker

2nd Edition

0934613656, 9780934613651

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago