Question
While the code given works for placing the ships on the board it could really stand to be organized a little better. This is what
While the code given works for placing the ships on the board it could really stand to be organized a little better. This is what your task is on the first part of the assignment.
the ShipInfo class has information about all ships but it does nothing for handling the images. It makes sense that there would be a Ship class that holds the general information and specialized ships like minesweep, frigate, battleship, and cruiser are derived from it.
Modify the ShipInfo class so that it is named Ship. Then derive each of the four ship types from Ship. At the very least the derived Ship will hold the images for the ship but you may want to have it hold the images in both directions. You are also going to need a mechanism to return all of the images back. I think it is best to have the class return Labels that hold each of the pieces. This way you are encapsulating the way the ship pieces are created. I will leave it up to you as to how to return a ship but you could return an array of Labels, an ArrayList of Labels just to name a couple.
When you are finished with this step your the program should run the same as it did when it was given to you with the exception that it is now more organized by using inheritance. This means you are going to have to modify the main code for the game to get your new classes to work.
I'm stuck on loading and returning the ship array
The first thing you should do is unzip the project and make sure you can get it to run. The project should randomly place ships around the ocean. This is simply a 2D array of labels that has pieces of the images placed in them. Of course creating the ships and placing them on the board properly is slightly complicated but fortunately for you that work has been done. What you will notice is that there are four different ship types with varying pieces. The following table shows this information The Shiplnfo class is used to keep information about each ship. It holds things like the number of pieces, the name of the ship, and the direction the ship should be placed on the ocean. While the code given works for placing the ships on the board it could really stand to be organized a little better. This is what your task is on the first part of the assignment. the Shiplnfo class has information about all ships but it does nothing for handling the images. It makes sense that there would be a Ship class that holds the general information and specialized ships like minesweep, frigate, battleship, and cruiser are derived from it. Modify the Shiplnfo class so that it is named Ship. Then derive each of the four ship types from Ship. At the very least the derived Ship will hold the images for the ship but you may want to have it hold the images in both directions. You are also going to need a mechanism to return all of the images back. I think it is best to have the class return Labels that hold each of the pieces. This way you are encapsulating the way the ship pieces are created. I will leave it up to you as to how to return a ship but you could return an array of Labels, an ArrayList of Labels just to name a couple. When you are finished with this step your the program should run the same as it did when it was given to you with the exception that it is now more organized by using inheritance. This means you are going to have to modify the main code for the game to get your new classes to work. The first thing you should do is unzip the project and make sure you can get it to run. The project should randomly place ships around the ocean. This is simply a 2D array of labels that has pieces of the images placed in them. Of course creating the ships and placing them on the board properly is slightly complicated but fortunately for you that work has been done. What you will notice is that there are four different ship types with varying pieces. The following table shows this information The Shiplnfo class is used to keep information about each ship. It holds things like the number of pieces, the name of the ship, and the direction the ship should be placed on the ocean. While the code given works for placing the ships on the board it could really stand to be organized a little better. This is what your task is on the first part of the assignment. the Shiplnfo class has information about all ships but it does nothing for handling the images. It makes sense that there would be a Ship class that holds the general information and specialized ships like minesweep, frigate, battleship, and cruiser are derived from it. Modify the Shiplnfo class so that it is named Ship. Then derive each of the four ship types from Ship. At the very least the derived Ship will hold the images for the ship but you may want to have it hold the images in both directions. You are also going to need a mechanism to return all of the images back. I think it is best to have the class return Labels that hold each of the pieces. This way you are encapsulating the way the ship pieces are created. I will leave it up to you as to how to return a ship but you could return an array of Labels, an ArrayList of Labels just to name a couple. When you are finished with this step your the program should run the same as it did when it was given to you with the exception that it is now more organized by using inheritance. This means you are going to have to modify the main code for the game to get your new classes to workStep 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