Answered step by step
Verified Expert Solution
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 hasmany 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 getteraccessor for the onedimensional 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 boat new Boat BMC Color. GREEN;
Boat boat new Boat BMX Color. RED ;
Boat boat new Boat UXB Color. YELLOW;
Harbor stock new Harbor ;
assertEquals null stock.getBoatAt ;
assertEquals null stock.getBoatAt ;
assertEquals null stock.getBoatAt ;
assertEquals null stock.getBoatAt ;
assertEquals null stock.getBoatAt ;
Hint: parkBoatAt is not just an accessor, and not just a mutator
assertEquals null stock.parkBoatAt boat;
Boat retrievedBoat stock.parkBoatAt boat;
assertEquals boat retrievedBoat;
retrievedBoat stock.parkBoatAt boat;
assertEquals boat retrievedBoat;
Boat inventory stock.getInventory ;
assertArrayEquals new Boat null null, null, boat null inventory;
stock.parkBoatAt boat;
The inventory is a carbon copy list of boats that is handed out to interested parties.
assertArrayEquals new Boat null null, null, boat null inventory; This is correct!
assertArrayEquals new Boat null boat null, boat null stock.getInventory;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started