Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Requirements: The computer must create at least 3 ships. The ships cannot all be the same size. The ships must be randomly placed within the

Requirements:

The computer must create at least 3 ships.

The ships cannot all be the same size.

The ships must be randomly placed within the array.

User communication:

Provide information to the user about the number of hits and misses. Provide a message about whether each guess is a hit or miss.

If the user guesses a number outside of the acceptable range, provide an error message.

Ending the game:

If the user hits all positions on all ships, the user wins.

If the user gets more than the maximum number of allowed misses, the user looses.

After the user wins or loses, ask them if they want to play again.

Programming Requirements

Place all of your code inside of one class: Battleship.java.

not required to create separate game/interaction classes.

Use at least one 1-dimensional array to represent the location of the ships.

Break your code up into logical methods.

Do not put all of your code inside of main. Write static methods and invoke those methods from main.

follow good principles of object-oriented programming, method design, and naming conventions.

Think carefully about what variables you need.

Use constants where appropriate.

Avoid duplicating code. Reuse code whenever possible.

To avoid problems with switching between reading numeric input and text input from the user, use this code to read in number input:

int number = Integer.parseInt(scan.nextLine());

For variables that you want to use across methods (for example, the array that represents the ship locations, the number of guesses, etc.), you can declare the outside of any method and make it static.

For example: private static int numberOfGuesses;

It's often a good idea to write a program like this in "layers."

For example, the random locations of the ships (e.g., System.out.println(Arrays.toString(shipLocations));

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions