Question
Java. Hello Please I need help with this assignmenmt, Its worth a lot and i have to start a fresh please. I have to implement
Java. Hello Please I need help with this assignmenmt, Its worth a lot and i have to start a fresh please. I have to implement few methods in an alreday created class. I will post the question, code and Link to the files just in case. The methods I need to do alone are commented "TODO//" Please help. Just the methods Link to drive please. https://drive.google.com/file/d/1z7bUplZpMsFC5Eweb1gR6sdV0H9EnuLV/view?usp=sharing
#Code
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class RadixSortMSD {
// *************************************************************
// TODO Write YOUR RADIX SORT HERE
// *************************************************************
public static void main(String args[]) {
// *************************************************************
// Change the input file by changing the line below.
// *************************************************************
String inputFile = "RadixSortMSD-Template/words-basictest.txt";
// Initialize a scanner to read the input file.
Scanner S = null;
try {
S = new Scanner(new File(inputFile));
} catch (FileNotFoundException e) {
System.out.println("Error: " + inputFile + "was not found.");
return;
}
// Read the first line of the file and convert it to an integer to see how many
// words are in the file.
int numWords = Integer.valueOf(S.nextLine());
// Initialize an array large enough to store numWords words.
String items[] = new String[numWords];
// Read each word from the input file and store it in the next free element of
// the items array.
int j=0;
while(S.hasNextLine()) {
items[j++] = S.nextLine().toUpperCase();
}
S.close();
System.out.println("Done reading " + numWords + " words.");
// Test and time your radix sort.
long startTime = System.nanoTime();
// *************************************************************
// TODO CALL YOUR RADIX SORT TO SORT THE 'items' ARRAY HERE
// *************************************************************
long stopTime = System.nanoTime();
// Uncomment this section if you want the sorted list to be printed to the console.
// (Good idea for testing with words-basictest.txt; leave it commented out though
// for testing files with more than 50 words).
/*
for(int i=0; i
System.out.println(items[i]);
}
*/
// Print out how long the sort took in milliseconds.
System.out.println("Sorted " + items.length + " strings in " + (stopTime-startTime)/1000000.0 + "ms");
}
}
For this problem you will write a method (or methods) to sort an array of strings using the MSD Radix Sort. For purposes of this assignment, you may assume that strings contain only the uppercase letters A through Z. You have been provided with an IntelliJ module RadixSortMSD-Template which includes a short main program that will load a data file containing strings to be sorted. There are several files provided named words-XXXXXX. txt where XXXXXX" denotes the number of words in the file. The file format starts with the number of words in the file, followed by one word per line. There is also a file words-basictest.txt which is a good set of words to use to determine whether your sort is running correctly The pseudocode for MSD Radix Sort from the notes is duplicated on the next page for your conve- nience. Note that we are removing the optimization of sorting short lists with insertion sort, a indicated by the strikethrough text. You may just always recursively radix sort any list with more than one element on itD Complete the following tasks: 1. Write your sort method(s) within the RadixSortMSD class. It should accept an array of strings as input, and return nothing. When the method returns, the array that was passed in should be in lexicographic order (i.e. dictionary order) 2. Call your sort at the spot indicated in the main) function. 3. Record in a file called a8q1.txt/doc/pdf the time in milliseconds it takes to sort 50, 100, 500, 1000, 10000, 50000, and 235884 items (there are input files with each of these numbers of words provided). Include this file in your assignment submission. 4. When you hand in RadixSortMSD.java, leave the input file set at words-basictest.txt so that it is easy for the markers to run your program on this input file to see that it works For this problem you will write a method (or methods) to sort an array of strings using the MSD Radix Sort. For purposes of this assignment, you may assume that strings contain only the uppercase letters A through Z. You have been provided with an IntelliJ module RadixSortMSD-Template which includes a short main program that will load a data file containing strings to be sorted. There are several files provided named words-XXXXXX. txt where XXXXXX" denotes the number of words in the file. The file format starts with the number of words in the file, followed by one word per line. There is also a file words-basictest.txt which is a good set of words to use to determine whether your sort is running correctly The pseudocode for MSD Radix Sort from the notes is duplicated on the next page for your conve- nience. Note that we are removing the optimization of sorting short lists with insertion sort, a indicated by the strikethrough text. You may just always recursively radix sort any list with more than one element on itD Complete the following tasks: 1. Write your sort method(s) within the RadixSortMSD class. It should accept an array of strings as input, and return nothing. When the method returns, the array that was passed in should be in lexicographic order (i.e. dictionary order) 2. Call your sort at the spot indicated in the main) function. 3. Record in a file called a8q1.txt/doc/pdf the time in milliseconds it takes to sort 50, 100, 500, 1000, 10000, 50000, and 235884 items (there are input files with each of these numbers of words provided). Include this file in your assignment submission. 4. When you hand in RadixSortMSD.java, leave the input file set at words-basictest.txt so that it is easy for the markers to run your program on this input file to see that it worksStep 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