Question: Implement a shuffle method that randomly sorts the data. public void shuffle ( long seed ) This method will take a seed value for use
Implement a shuffle method that randomly sorts the data.
public void shufflelong seed
This method will take a seed value for use with the Random class. A seed value makes it so the same sequence of "random" numbers is generated every time.
To implement this method, create an instance of the Random class using the seed: Random rng new Randomseed;
Then, visit each element. Generate the next random number within the bounds of the list, and then swap the current element with the element that's at the randomly generated index.
Here are the provided codes:
Demojava
import java.util.Scanner;
public class Demo
public static void mainString args
Scanner keyboard new ScannerSystemin;
System.out.printlnEnter seed for random number generator";
long x keyboard.nextLong;
MyLinkedList list new MyLinkedList;
list.addA;
list.addB;
list.addC;
list.addD;
list.addE;
System.out.printlnNot shuffled";
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex;
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex ;
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex ;
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex ;
System.out.printlnlist;
list.clear;
TestBench.addToListlist;
System.out.printlnNot shuffled";
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex;
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex ;
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex ;
System.out.printlnlist;
System.out.printlnShuffle ;
list.shufflex ;
System.out.printlnlist;
TechBench.java
import java.util.AbstractList;
public class TestBench
public static AbstractList buildList
return addToListnew MyLinkedList;
public static AbstractList addToListAbstractList list
String data "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for int x ; x data.length; x
list.adddatacharAtx;
return list;
public static void testAbstractList list
System.out.println Beginning Tests ;
System.out.printlnNo changes";
System.out.printlnlist;
System.out.printlnTesting size;
System.out.printlnlistsize;
System.out.printlnTesting addint index, E element;
list.add "AAA";
list.addBBB;
list.addCCC;
list.addDDD;
list.addlistsize "EEE";
System.out.printlnlist;
System.out.printlnTesting getint index;
System.out.printlnElement at : list.get;
System.out.printlnElement at : list.get;
System.out.printlnElement at : list.get;
System.out.printlnElement at : list.get;
System.out.printlnElement at last position: list.getlistsize;
System.out.printlnTesting removeint index;
System.out.printlnlistremove;
System.out.printlnlistremove;
System.out.printlnlistremove;
System.out.printlnlistremove;
System.out.printlnlistremove;
System.out.printlnlistremovelistsize;
System.out.printlnlist;
System.out.printlnTesting setint index, E element;
list.setQQQ;
list.setWWW;
list.set "EEE";
list.setRRR;
list.setTTT;
list.setTTT;
list.setlistsizeYYY;
System.out.printlnlist;
System.out.printlnTesting indexOfObject o;
System.out.printlnindexOf QQQ: list.indexOfQQQ;
System.out.printlnindexOf WWW: list.indexOfWWW;
System.out.printlnindexOf D: list.indexOfD;
System.out.printlnindexOf HELLO: list.indexOfHELLO;
System.out.printlnindexOf RRR: list.indexOfRRR;
System.out.printlnindexOf TTT: list.indexOfTTT;
System.out.printlnindexOf GOODBYE: list.indexOfGOODBYE;
System.out.printlnTesting lastIndexOfObject o;
System.out.printlnlastIndexOf QQQ: list.lastIndexOfQQQ;
System.out.printlnlastIndexOf WWW: list.lastIndexOfWWW;
System.out.printlnlastIndexOf D: list.lastIndexOfD;
System.out.printlnlastIndexOf HELLO: list.lastIndexOfHELLO;
System.out.printlnlastIndexOf RRR: list.lastIndexOfRRR;
System.out.printlnlastIndexOf TTT: list.lastIndexOfTTT;
System.out.printlnlastIndexOf GOODBYE: list.lastIndexOfGOODBYE;
System.out.printlnTesting clear;
list.clear;
System.out.printlnlist;
System.out.printlnTesting clearsecond time;
list.clear;
System.out.printlnlist;
System.out.printlnRefilling the list";
addToListlist;
System.out.printlnlist;
System.out.println Ending Tests ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
