Create a test program that creates a ships collection and


OO Design and implementation

Our battleships game needs to store a set of ships

Create a new class called Ships

Ships should have the following properties
• A way to store a collection of the Ship class from last week
   o If you do not have working code from last week please ask your teacher.
   o Does the Ships class represent the IS-A (inheritance) or the HAS-A (composition) relationship? Design your class accordingly. Use a suitable generic collection classes.
• void Add(Ship)
   o This method that allows you to add a ship
   o The add method should validate that no ships are overlapping. How you do this is up to you to design. Feel free to discuss it in the forums but do not post code
   o If there is a collision this method should throw a suitable exception
• void Clear()
   o this method that allows you to reset the collection
• boolSunkMyBattleship{get; private set}
   o this readonly property returns true if the battleship has been sunk
   o The private set part is optional depending on how you implement it. But the property should be readonly to callers of the class
• bool Attack(int x, int y)
   o this method that attacks the collection of ships and marks any positions as hit
   o This should also mark the ship as Sunk if all positions are hit
   o The method should return an indication of a hit (true) or a miss (false)
   o Your attack method should validate x and y are positive integers and throw a suitable exception if they are not

You should choose the correct types and access modifiers for each type.

You may add as much code and data structures as you like to fulfill all of the requirements.

Create a test program that creates a Ships collection and populates it with some ships - you may hard code positions though your teacher will test the code with different ones so make sure to test your code well.

The Test code should ask the user for X, Y positions and attach the ship collection until the battleship is hit.

There is no need to output any UI but it might help you test if you do ;-) It does not have to look like a battleship game. Remember this is purely code to help you test your Ships data structure

Attachment:- Programming Assignment.zip

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: Create a test program that creates a ships collection and
Reference No:- TGS02223535

Expected delivery within 24 Hours