Question
Hello, I need help on the following assignment. I will be sure to like/comment, and please code in java in a beginning coder style w/comments
Hello, I need help on the following assignment. I will be sure to like/comment, and please code in java in a beginning coder style w/comments so I can understand better, thank you!
Pasted below is the driver, GUI, and puzzle classes. The GUI class is posted in a pastebin link since chegg only lets me make the question so long.
//DRIVER.JAVA
public class Driver {
public static void main(String[] args) { //change this number to how many tiles you want int numberOfTiles = 9; SlidingSquarePuzzle fibonaciSlider = new SlidingSquarePuzzle(numberOfTiles); // fibonaciSlider.getTileList()[0] = 1; // fibonaciSlider.getTileList()[1] = 1; // fibonaciSlider.getTileList()[2] = 2; // fibonaciSlider.getTileList()[3] = 3; // fibonaciSlider.getTileList()[4] = 5; // fibonaciSlider.getTileList()[5] = 8; // fibonaciSlider.getTileList()[6] = 13; // fibonaciSlider.getTileList()[7] = 21; GUI.init(fibonaciSlider); }
}
//SLIDING SQUARE PUZZLE . JAVA
import java.util.Arrays; import java.util.Random;
public class SlidingSquarePuzzle { private int [] tileList; public SlidingSquarePuzzle() { this(16); } public SlidingSquarePuzzle(int size) { tileList = size 0; i--) { int j = rand.nextInt(i + 1); int temp = tileList[j]; tileList[j] = tileList[i]; tileList[i] = temp; } }while(!this.isSolvable()); }
}
//GUI.JAVA
https://pastebin.com/JgH3Lc79
Intro Dear Developer, It seems an overzealous programmer tried to create a Fibonacci slider puzzle from our old code. This brought up the fact there is a data integrity issue in our SlidingSquarePuzzle class. It makes sense because the class's data only consists of an int[]. Since, you are new this is a good opportunity to get your feet wet. I want you to change the offending code and help shore up our security hole. I've attached their Driver and the GUI and slidingSquare Puzzle files. I've also commented out the offending code. Part 1: Edit the getTileList method 1. Why does this method create a security issue? a. Because you have direct access to the array. As seen in the driver, you have the reference to the array. 2. Change the method to getTile(int index) and return an int at the specific index of tileList. 3. This will break the GUI code. You will need to replace instances of gettilelist with getTile. a. Even though you have changed everything, your code will not work. b. This is due to the return data being primitive. You cannot assign data to a primitive data type. 4. Add a length method that returns the tilelist.length. a. Replace where necessary. Part 2: Add a blankPos field 1. This replaces the blankPos field in GUI. 2. Add a field called blankPos. Initialize it in the Constructors. 3. Add a getter for blankPos. 4. Add a private update method for blankpos. This will be called anytime tileList changes. 5. Replace blankPos for ssp.getBlankPos (). 6. Delete old code: a. For-loop from the newGame method in GUI b. blankpos = newBlankPos;& ssp.getTileList() [blankPos] 0; from the if (direction != 0) inside the GUI constructor. Part 3: Add a swaplndexes method 1. This method will take two indexes and swap their positions. 2. Check to make sure one of the parameters is the index of the blankPos, otherwise do nothing. 3. Update the blankpos. 4. You will need to replace ssp.getTileList() [blankpos] ssp.getTileList() [newBlankPos] with it. 5. Update the shuffle method. a. Where should you call the swapIndexes method in shuffleStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started