Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

The purpose of this programming project is to demonstrate understanding of 2 dimensional arrays and the creation, implementation, and use of a simple instantiable class. You are to design a class "WherelsWaldo.java" which represents Waldo in an unknown seat location at an auditorium. Seating in an auditorium is made up of rows, identified with alphabetic letters, and seats on a given row identified with a number. Starting with row A from the stage to the back of the auditorium, row letters are labeled in ascending order with seat numbers increasing from the audience's left. For example, with rows and seat numbers facing the stage on the right, are listed as such: During instantiation (or creation) of an object of this class, each seat on each row will be initialized as empty (you will actually use the space ' character for this purpose) and a random seat location where Waldo is Sitting will be chosen. For this purpose, the character "W" will be placed in this random location. Further details on the constructor and the WherelsWaldo class is listed on pages 2-3. An object of this class is used as a game for two players to take turns searching for Waldo, one seat at a time until the troublesome Waldo is 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 "PlayWaldoGame.java") DETAILS Because the Waldo is hiding (or placed) in a random location of the auditorium, you will need to import the Random class in the WherelsWaldo class. Name your class "WherelsWaldo.java". Fields (of course, all fields are private): A character (char) array named myAudi torium. Since a 2-D array is used to simulate the seats in an A character (char) array named myAudi torium. Since a 2-D array is used to simulate the seats in an auditorium, the actual auditorium row A will be row index 0 , row B will be row index 1 , and so on. The actual auditorium seat 1 on each row will be column index 0 , seat 2 will be column index 1 , and so on. Two integers that will hold the row and seat where the Waldo is hiding, named myRowLocation and mySeatLocation. A char named myWinner which will be assigned the player's character when a player finds Waldo (the driver program uses digits ' 1 ' and ' 2 ' to more clearly distinguish the players from Waldo). A boolean named myFound which is set to true when Waldo is found. Receives two integer parameters as the user's input for the number of rows and seats per row of the auditorium in which Waldo is hiding. The constructor instantiates the 2D array "myAuditorium" as a character array with the first parameter for the rows (theRows) and the second parameter as the columns (theSeats). Initialize myAuditorium cells, each to contain a space " (done with single quotes) Set myRowLocation (Row Waldo is on) randomly based using the first parameter Set mySeatLocation (Seat Waldo is in) randomly based using the second parameter Set myAuditorium[myRowLocation][mySeatLocation] to the char 'W' Set myWinner to a single space Set myFound to false Tethods (be certain to declare the header of each method as listed here): seatSearchedAlready receives the row (as a char: A,B,C, etc.) and seat (as an int in the range of 1 to total seats to be searched... need to subtract 1 to properly index the column location in the myAuditorium array) and returns true if the seat has already been searched, false otherwise. waldoLocation receives the row (as a char: A, B, C, etc.) and seat (as an int in the range of 1 to total seats to be searched... need to subtract 1 to properly index the column location in the myAuditorium array) to be searched and returns true if the row and seat is where Waldo is hiding, waldoLocation receives the row (as a char: A,B,C, etc.) and seat (as an int in the range of 1 to total seats to be searched... need to subtract 1 to properly index the column location in the myAuditorium array) to be searched and returns true if the row and seat is where Waldo is hiding, false otherwise. This method should NOT change any of the fields. indicesOK receives the row (as a char: A,B,C, etc. ) and seat (as an int in the range of 1 to total seats to be searched.) to be searched and returns true if the row and seat 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. Keep in mind, you need to convert the row letters A, B, C, etc to 0,1,2, etc. respectively and the seats of 1,2,3, etc. to 0,1,2, etc to properly check if the indices are valid). numberOfRows returns an int of how many rows are in the auditorium. numberOfSeats returns an int of how many seats are in each row of the auditorium. searchSeat receives the row (as a char: A,B,C, etc. ) and seat (as an int in the range of 1 to total seats to be searched.) to be searched and also the current player (as a char type) and returns true if Waldo is found, false otherwise. If Waldo is NOT found, searchSeat also sets the myAuditorium array at the received row and seat location to the received player value (a '1' or a '2') OR, when found, sets the myWinner field to the current player AND sets myFound to true. toString displays the current myAuditorium array and it's contents EXCEPT the location of Waldo which remains hidden until he is found at which point toString will be called (by the driver) and both the player who found Waldo and a 'W' will be displayed in the same cell.... 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, because Waldo has decided to hide in an auditorium and not a matrix, it would make more visual sense to have the first row (row A ) displayed to the right, second row (row B ) to the left of row A, and so on... The seat locations (columns) within a given row are displayed from top to bottom. To save words, look closely at the sample run provided on the next page. The output of your auditorium should look identical to what is seen in the sample run on page 4 below. driver program PlayWaldoGame.java, randomly chooses which player should begin)

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_2

Step: 3

blur-text-image_3

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

List the major functions of the liver.

Answered: 1 week ago

Question

Define turnover intent.

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago