Demonstrate understanding of two dimensional arrays

Assignment Help JAVA Programming
Reference no: EM131864542

Programming Assignment

The purpose of this programming project is to demonstrate understanding of 2 dimensional arrays and the creation, implementation, and use of a simple class.

You are to design a class "SweeperGame.java" which represents a piece of buried treasure in the ground that must be found on a grid representing the ground. During the instantiation (or creation) of an object of this class, each space in the grid will be initialized as empty (you will actually use a space ‘ ' character for this purpose) and a random spot on the grid will be chosen for the location of the buried treasure. For this purpose, the character "T" will be placed in this random location. Further details on the constructor are listed below.

An object of this class is used as a game for the player to take a turn to guess where the treasure is buried until the treasure has been found. The instantiation of this object and the search will be performed by a "driver" program which has been provided to you allowing you to only have to concentrate on developing the class (the driver program is in the file "SimpleSweeper.java").

DETAILS

The treasure is placed in a random location in the ground, so you will need to import the "Random" class in the SweeperGame class.

Name your class "SweeperGame.java".

The fields of you object should be private. This is to make sure you are encapsulating your data, by making sure fields are private you will ensure that the only access to those fields is through your getters or setters and are able to limit what data can be accessed.

Fields (MUST BE PRIVATE):

• A character (char) array named gameBoard. This represents the grid in which the treasure is hiding. The bottom and leftmost square of this grid will be (0,0).

• Two integers that will hold the X and Y position of the buried treasure in the grid, named treasureX and treasureY.

• A integer called totalMoves that keep tracks of how many times the uses has searched for the treasure.

• A boolean called found that keep tracks of whether the treasure has been found.

Constructor:

• Receives two integer parameters as the user's input for the number of height and width of the grid where the treasure is buried.

• The constructor instantiates the 2D array "gameBoard" as a character array with the first parameter for the height (height) and the second parameter as the width (width).

• Initialize gameBoard's cells, each to contain a space ‘ ‘ (done with single quotes)

• Set treasureX (the x coordinate of the treasure) randomly based using the first parameter

• Set treasureY (the y coordinate of the treasure) randomly based using the second parameter

o Please think carefully about how you use the X and Y coordinates throughout your program.

• Set gameBoard[treasureY][treasureX] to the char ‘T'

• Set totalMoves to 0

• Set found to false

Methods:

• beenSwept receives the x coordinate and y coordinate to be searched and returns true if the space has already been searched, false otherwise.

• treasureFound receives the x coordinate and y coordinate to be searched and returns true if the treasure is found there, false otherwise.

• checkOutOfBounds receives the x coordinate and y coordinate to be searched and returns true if the values are within the array indices range, false otherwise (used to check that these indices will not cause an error when applied to the array).

• getBoardHeight returns the height of the board.

• getBoardWidth returns the width of the board.

• getTotalMoves returns the total amount of moves taken.

• digSand receives the x coordinate and y coordinate to be searched returns true if the treasure is found, false otherwise and sets the found field to true. If the treasure is NOT found digSand also sets the gameBoard array at the received x coordinate and y coordinate location to the "Manhattan distance" to the treasure. Increment the number of moves taken if the treasure has not been found and the space has not been previously searched.

• toString displays the current gameBoard array and it's contents EXCEPT the location of the treasure which remains hidden until he/she is found at which point toString will be called (by the driver) and the ‘T' will be displayed.

NOW, and perhaps the awkward portion of the toString output. Normally, when displaying a 2D array, the [0][0] cell is displayed in the upper left corner as with matrices. However, we will be displaying the array like a regular mathematical graph so the bottom left coordinates will be (0,0) and increase as we go up or to the right. Your output should look the same as what is seen on the next page in the sample run.

Manhattan Distance

Manhattan distance is described as from wikitionary:

Manhattan distance (plural Manhattan distances)

1. The distance between two points in a grid based on a strictly horizontal and/or vertical path (that is, along the grid lines), as opposed to the diagonal or "as the crow flies" distance. The Manhattan distance is the simple sum of the horizontal and vertical components, whereas the diagonal distance might be computed by applying the Pythagorean theorem.

Here is a sample output to better understand what the Manhattan distance is. It is simply calculated by finding the vertical and horizontal distance to the treasure.

,~,~,~,~,
;5:4;3:2;
`~`~`~`~`
;4:3;2:1;
`~`~`~`~`
;3:2;1:T;
`~`~`~`~`
;4:3;2:1;
`~`~`~`~`

Attachment:- Tax-Computation.rar

Reference no: EM131864542

Questions Cloud

Distinguish between the terms position : 1. Relative to directional control valves, distinguish between the terms position, way, and port.
What is the common-size statement value of inventory : A firm has sales of $756,000, net income of $60,500, net fixed assets of $402,000, What is the common-size statement value of inventory?
What are integrated hydraulic circuits : 1. Relative to the use of cartridge valves, what are integrated hydraulic circuits?
Discuss idea of an ideal street-level administrator : Describe "ideal" street-level administration from the traditional managerial, New Public Management, political, and legal perspectives.
Demonstrate understanding of two dimensional arrays : The purpose of this programming project is to demonstrate understanding of 2 dimensional arrays and the creation, implementation, and use of a simple class.
Determine the difference in load-carry capacity : Determine the difference in load-carry capacity between extension and retraction if the pressure is constant.
Describe at least two specific benefits to hiring a veteran : Describe at least two specific benefits to hiring a veteran. Draw from your own personal experiences and what you have learned from our readings and videos.
Maximum pressure developed by the cushion : The pump pressure relief valve selling equals 500 psi. Find the maximum pressure developed by the cushion.
Describe the purpose of each organization : Describe the purpose of each organization and explain its significance to the early childhood field. Provide a citation for each organization.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd