Java assignment 3

rjnaqnjbbq
timer Asked: Feb 19th, 2019

Question Description

Instructions are on the attached DOC below. Please make sure to test the code to make sure that it works with no errors.

Thank you!

Unformatted Attachment Preview

Lab 3 NOTE: For this lab, you will get 5 points for a valid attempt if turned in by the due date. The main new component in this lab, multidimensional arrays, are in Chapter 7 and were reviewed in class. TIP: Remember, don't be overwhelmed by all the details. Simply focus on one line at a time as the instructions walk you through the creation of the app. *** Instead of "work" or an "assignment"... THINK OF THIS AS A FUN PROGRAMMING CHALLENGE! Never forget, coding is fun! Seriously, that's like in the Bill of Rights or something like that. *** 1. SUMMARY a. Build an app that randomly creates a 10 by 10 grid of 0s and 1s where the 0s represent open spaces and 1s represent blocked spaces (like we did in class), and then see if user can navigate from position 0,0 to where either the first index or second index equal 9 w/o hitting a 1. In other words the user must move clear across the grid without hitting a 1 or the game is over. b. This lab will involve the following new features: i. java.util.SecureRandom class ii. Two-dimensional arrays 2. DETAILS a. There won't be as much detail on the grid creation part of this as we already created an example of the grid in class together. b. Classes i. GameGrid_Test 1. Will have main method and will instantiate instance of GameGrid and call run... that's it. ii. GameGrid 1. This will have one public "run" method and this will be called by the GameGrid_Test class's main method. ALL CODE can be in the "run" method. a. Create game grid: This method will create a game grid (two-dimensional int array) and fill each cell with 1 or 0 randomly using the Random class. i. There should be a LESS CHANCE to have a 1 fill the spot than a 0. 1. Reminder Tip: a. Set an int variable called iWallChance to a number like 30, and then use the bound parameter of the SecureRandom class’s nextInt method to control the range of possible numbers just like we did in class. b. Then you'd compare the returned random number to see if it's less than your iWallChance variable. c. If it was less, you'd set that cell to 1... if not, then the cell would be set to 0. b. Change the location [0][0] of the grid to 0 so that the first space is open and not a wall because that's where we'll start our user. c. Create two int variables for the user's position... iUserRow and iUserCol... and set each to 0. d. Create a boolean variable for the following loop to know when to exit. e. Create while loop for moving: This loop will keep asking user whether to move down or to the right. i. If the user chooses down, then that will affect the first array value (row); and if the user chooses right, that will affect the second array value. ii. With each user answer, adjust the iUserRow or iUserCol positions depending whether down or right by increasing the correct variable by 1. iii. Check if this new user position is a 1 in the grid. If it's a 1, tell the user they failed and exit loop. iv. If it was not a 1, then check if either user position is now a 9. 1. If one of them is 9, they have reached either the right side or bottom and tell them they have won and exit loop. f. After loop is over, then print out the grid as we did in class (nested for loop (which is a for loop within a for loop)). i. With each cell, before you print out 0 or 1, check if that cell (x and y) equals the user position (iUserRow and iUserCol). 1. If it does, print out a capital X in that spot. 2. Otherwise, simply print out the value of that spot in the array. 3. Printing tip: Remember in class that we used System.out.print... within the inner for loop for printing so no line break was done. Then use System.out.println(""); after the closing curly bracket of the inner for loop but before the closing curly bracket of the outer for loop. That way each row will be printed out on a separate line for a nice readable layout. 3. TURNING IN LAB: a. Turn your lab into Blackboard. b. IMPORTANT: DO NOT ZIP your folders/files please. c. Turn in just the two raw java files for this lab.
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Related Tags

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors