Question

Programming Language : JAVA Write a class named Ship. Its purpose is to model a ship...

Programming Language : JAVA

Write a class named Ship. Its purpose is to model a ship in the BattleShip game and its placement on the Battleship board.

Ships exist on a 10 x 10 battleship board with ten rows labeled A through J and columns labeled 1 through 9 and the final column labeled 0 to indicate the tenth column.

We will refer to the Ship placed on the board at the origin which the pair (r,c) where in the below example r is the row D and the column is 4. The example ship extends downward with Direction.VERTICAL with a length of 3. The origin of a Ship is considered at either (1) the left most square with the remainder extending horizontal Direction.HORIZONTAL and to the right, or (2) the top most square with the remainder extending vertical Direction.VERTICAL and down. Ships may not be placed diagonal. At any point, the ship must exist on the grid. The following example perspective is from the Viewer.PLAYER perspective.

When the opponent fires a shot with the call to the checkShot('E',4) method and it hits the ship, the square at coordinates that is hit changes to a +

When the opponent has fired shots that have hit all the squares that belong to the ship, all the ship’s squares values change to x and the ship’s state changes to sunk.

The display of the ship also depends upon the perspective of the viewer. When the ship is viewed by the Viewer.OPPONENT, squares that have not been hit should return -. Any hits should appear as + and all the squares should appear as x for a ship whose state is sunk. The ship shown above with one hit appears as following when the viewer state is set to PLAYER.OPPONENT.

The following public methods should be supported in Ship:

public Ship()
public Ship(char row, int col, Direction d, int l)
public void setViewer(Viewer w)
public void clearDeck()
public char getSquare(char row, int col)
public boolean isSunk()
public boolean checkShot(char row, int col)
public boolean hasSquare(char row, int col)
public void setOrientation(Direction newDirection)
public void setLength(int newLength)
public void setOrigin(char row, int col)
public String toString()
public String gridView()

You will need the following files in additon to compile your program. Do not submit them.

public enum Viewer {
   PLAYER, OPPONENT;
}
public enum Direction {
   HORIZONTAL, VERTICAL;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Ship

{

public:

Ship();

Ship(char row,int col,Direction D,int l);

void SetViewer(Viewer w);

void clearDeck();

void getChar(int row,int col);

boolean isSunk();

boolean checkShot(char row,int col);

boolean hasSquare(char row,int col);

void setOrientation(Direction newDirection);

void setLength(int newLength);

void setOrigin(char row,int col);

String toString();

String gridView();

enum Viewer{PLAYER,OPPONENT};

enum Direction{HORIZONTAL,VERTICAL);

}

Add a comment
Know the answer?
Add Answer to:
Programming Language : JAVA Write a class named Ship. Its purpose is to model a ship...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every...

    Make sure to include: Ship.java, ShipTester.java, Location.java, LocationTester.java, Grid.java, GridTester.java, Player.java, PlayerTester.java, battleship.java. please do every part, and include java doc and comments Create a battleship program. Include Javadoc and comments. Grade 12 level coding style using java only. You will need to create a Ship class, Location class, Grid Class, Add a ship to the Grid, Create the Player class, the Battleship class, Add at least one extension. Make sure to include the testers. Starting code/ sample/methods will be...

  • Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner...

    Hello I am having trouble with a connectFour java program. this issue is in my findLocalWinner method, it declares a winner for horizontal wins, but not for vertical. if anyone can see what im doing wrong. public class ConnectFour { /** Number of columns on the board. */ public static final int COLUMNS = 7; /** Number of rows on the board. */ public static final int ROWS = 6; /** Character for computer player's pieces */ public static final...

  • JAVA Only Help on the sections that say Student provide code. The student Provide code has...

    JAVA Only Help on the sections that say Student provide code. The student Provide code has comments that i put to state what i need help with. import java.util.Scanner; public class TicTacToe {     private final int BOARDSIZE = 3; // size of the board     private enum Status { WIN, DRAW, CONTINUE }; // game states     private char[][] board; // board representation     private boolean firstPlayer; // whether it's player 1's move     private boolean gameOver; // whether...

  • This is my code for a TicTacToe game. However, I don't know how to write JUnit...

    This is my code for a TicTacToe game. However, I don't know how to write JUnit tests. Please help me with my JUnit Tests. I will post below what I have so far. package cs145TicTacToe; import java.util.Scanner; /** * A multiplayer Tic Tac Toe game */ public class TicTacToe {    private char currentPlayer;    private char[][] board;    private char winner;       /**    * Default constructor    * Initializes the board to be 3 by 3 and...

  • Assignment - Battleship In 1967, Hasbro toys introduced a childrens game named “Battleship”. In the next...

    Assignment - Battleship In 1967, Hasbro toys introduced a childrens game named “Battleship”. In the next two assignments you will be creating a one-player version of the game. The game is extremely simple. Each player arranges a fleet of ships in a grid. The grid is hidden from the opponent. Here is an ASCII representation of a 10x10 grid. The ‘X’s represent ships, the ‘~’s represent empty water. There are three ships in the picture: A vertical ship with a...

  • Complete the program that solves the Eight Queens problem in java only please (pages 318 through...

    Complete the program that solves the Eight Queens problem in java only please (pages 318 through 320). The program’s output should look similar to: |1|0|0|0|0|0|0|0| |0|0|0|0|0|0|1|0| |0|0|0|0|1|0|0|0| |0|0|0|0|0|0|0|1| |0|1|0|0|0|0|0|0| |0|0|0|1|0|0|0|0| |0|0|0|0|0|1|0|0| |0|0|1|0|0|0|0|0| PlaceQueens(in currColumn:integer) //places queens in columns numbered currColumn through 8 If (currColumn>8){ The problem is solved } Else { While(unconsidered squares exist in curr column and the problem is unsolved ){ Determine the next square in column currColumn that is not under attack by a queen in an...

  • Chapter 8 Exercise 36, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY. 8.36 (Latin square)...

    Chapter 8 Exercise 36, Introduction to Java Programming, Tenth Edition Y. Daniel LiangY. 8.36 (Latin square) A Latin square is an n-by-n array filled with n different Latin letters, each occurring exactly once in each row and once in each column. Write a program that prompts the user to enter the number n and the array of characters, as shown in the sample output, and checks if the input array is a Latin square. The characters are the first n...

  • I need help finishing my C++ coding assignment! My teacher has provided a template but I...

    I need help finishing my C++ coding assignment! My teacher has provided a template but I need help finishing it! Details are provided below and instructions are provided in the //YOU: comments of the template... My teacher has assigned a game that is similar to battleship but it is single player with an optional multiplayer AI... In the single player game you place down a destroyer, sub, battleship, and aircraft carrier onto the grid.... Then you attack the ships you...

  • For your Project, you will develop a simple battleship game. Battleship is a guessing game for...

    For your Project, you will develop a simple battleship game. Battleship is a guessing game for two players. It is played on four grids. Two grids (one for each player) are used to mark each players' fleets of ships (including battleships). The locations of the fleet (these first two grids) are concealed from the other player so that they do not know the locations of the opponent’s ships. Players alternate turns by ‘firing torpedoes’ at the other player's ships. The...

  • This is my code for my game called Reversi, I need to you to make the...

    This is my code for my game called Reversi, I need to you to make the Tester program that will run and complete the game. Below is my code, please add comments and Javadoc. Thank you. public class Cell { // Displays 'B' for the black disk player. public static final char BLACK = 'B'; // Displays 'W' for the white disk player. public static final char WHITE = 'W'; // Displays '*' for the possible moves available. public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT