Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROGRAMMING : NEED THE CODE AND JUNIT TEST CASE TO COPARE TO THE SECOND FILE . READ BELOW You are planning a road trip

JAVA PROGRAMMING : NEED THE CODE AND JUNIT TEST CASE TO COPARE TO THE SECOND FILE . READ BELOW

You are planning a road trip and want to create a playlist of your favorite songs. Assume that thesong titles are in an array of strings. Create a shuffle of yoursongs (permutation of your original songs).Use the FisherYates shuffle algorithm that works in O(n) running time. We will use a methodthat creates pseudo-randomnumbers(see end for help) in O(1) running time.The basic idea is to start from the last element, swap it with a randomly selected element from the whole array (including last). In the next step you will consider the array from 0 to n-2 (size reduced by 1), and repeat the process untilyou reachthe first element.Write a programthat usesthe provided Playlist.txt as inputand outputsthe shuffled array in a file called LastNameFirstNamePlaylist.txt.Follow the next pseudocode:To shuffle an array a of n elements (indices 0..n-1):for i from n -1 downto 1j = random integer with 0

Instructions for developing JUnit:

To compare two text files in Junit, you can try the following pseudocode.

Use BufferedReader to read the input files.

BufferedReader Out=new BufferedReader (new FileReader ());

BufferedReader In=new BufferedReader (new FileReader ());

while ((expectedLine = In.readLine ()) != null) {

String actualLine = Out.readLine ();

assertEquals (expectedLine, actualLine);

}

Set seed value as 20.

Random r=new Random();

r.setSeed(20);

Compare the output file with attached see next:

if you use

double d = random.nextDouble();

int j = (int)(d*arr.length);

use Target1.txtimage text in transcribed

else if you use

else if you use

Random r = new Random(0);

r.setSeed(20);

for (i = n-1 to 0) {

int j = r.nextInt(i);

swap(arr[i],arr[j]);

}

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

Step: 3

blur-text-image

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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

2: 3 4 5 6 DO 8 9 **** 10 | 11 12 13 14 15 16 17 18 19 444 444

Answered: 1 week ago