Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M92692896

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As