Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAKE SURE THE OUTPUT MATCHES PLEASE Heres the picture I will post it again below with the rest of the instructions as well: The code

MAKE SURE THE OUTPUT MATCHES PLEASE

Heres the picture I will post it again below with the rest of the instructions as well:

The code must print out the same thing as the picture pleaseeee

image text in transcribed

Ive already posted about this a couple time but no one matches the output correctly so please if you attempt to do it match the output thank you

Create the SortAlgs file and Main file separately and please label them

Also attempt the bonus and label it and where it goes too thank you and have a nice day

If you cant do the bonus thats fine

Thank you so much and sorry for posting so much about this one

*The instructions in the PDF say to use the given SortAlgs.java. That's a mistake! You are supposed to create the sortAlgs file.

image text in transcribed

image text in transcribed

Container Class:

public class Container { private int key; private String msg; public Container(int var1) { this(var1, (String)null); } public Container(int var1, String var2) { this.key = var1; this.msg = var2; } public int getKey() { return this.key; } public String getMsg() { return this.msg; } public String toString() { return "" + this.key; } }

Also, try to attempt the bonus that might pop up

Below is the template needed for it

import java.util.Scanner; public class GetBonus { private static final String SECRET_CODE = "tgtscftattfloewittlactaiassb"; private static final String SECRET_CODE_2 = "\"tgtscftattfloewittlactaiassb\""; private static Scanner scanner; private static long startTime; public GetBonus() { } public static void main(String[] var0) throws InterruptedException { scanner = new Scanner(System.in); int[] var2 = new int[]{1, 7, 5}; Container[] var1 = sentence1(); startTimer(); SortAlgs.cocktailSort(var1); printWords(var1, (int)stopTimer() * var2[0]); var1 = sentence2(); startTimer(); SortAlgs.quickSort(var1); printWords(var1, (int)stopTimer() * var2[1]); var1 = sentence3(); startTimer(); SortAlgs.countingSort(var1); printWords(var1, (int)stopTimer() * var2[2]); System.out.println(); System.out.print("Secret Code: "); String var3 = scanner.nextLine().trim().toLowerCase(); if (!var3.equals("tgtscftattfloewittlactaiassb") && !var3.equals("\"tgtscftattfloewittlactaiassb\"")) { System.out.println("\u001b[31mACCESS DENIED!\u001b[0m"); } else { System.out.print("\u001b[32mACCESS GRANTED!\u001b[0m"); sleep(1000); System.out.println(); System.out.println(); textCrawl("**Write the words 'I FOUND THE BONUS' in your header comment so I know you found this**", 30); System.out.println(); sleep(1000); System.out.println(); textCrawl("For 8 Bonus Points (each):", 30); System.out.println(); textCrawl(" Implement Comb Sort, Merge Sort and/or Radix Sort from the extra notes (i.e. Part 3).", 30); System.out.println(); textCrawl(" Add the resulting sorted array to the output", 30); System.out.println(); textCrawl(" in the same format as the other algorithms", 30); System.out.println(); textCrawl(" Also, add the runtime to the end of the timings", 30); System.out.println(); textCrawl(" in the same format as the other algorithms", 30); System.out.println(); System.out.println(); sleep(1000); textCrawl("Each sorting algorithm you implement gives you 8 bonus points for a max of 24 points!", 30); System.out.println(); System.out.println(); } } private static Container[] sentence1() { return new Container[]{new Container(2, "secret"), new Container(0, "the"), new Container(26, "this"), new Container(-5, "To"), new Container(32, "assignment"), new Container(-3, "get"), new Container(12, "for"), new Container(8, "code")}; } private static Container[] sentence2() { return new Container[]{new Container(-1, "the"), new Container(3000, "lines"), new Container(0, "first"), new Container(150, "these"), new Container(5, "of"), new Container(10, "each"), new Container(-8, "Take"), new Container(26, "word"), new Container(200, "three"), new Container(1, "letter"), new Container(105, "in")}; } private static Container[] sentence3() { return new Container[]{new Container(5, "into"), new Container(2, "concat"), new Container(12, "string"), new Container(0, "And"), new Container(2, "them"), new Container(5, "a"), new Container(2, "all"), new Container(9, "single"), new Container(12, "below")}; } private static void printWords(Container[] var0, int var1) throws InterruptedException { Container[] var2 = var0; int var3 = var0.length; for(int var4 = 0; var4   Your objective is to implement the following three algorithms: - From the list of quadratic time algorithms: Cocktail Sort - From the list of linearithmic time algorithms: Quick Sort - From the list of linear time algorithms: Counting Sort All of these algorithms are explained in detail in the notes and some or all of the pseudocode behind them is given. You will create a public class called SortAlgs inside of the given SortAlgs.java file. Inside this class will be three public methods, cocktailsort, quicksort and countingSort. Each of these public methods take in one, and only one parameter - that being an array of container objects (which is described below). The methods do not return anything as they either modify the list "in-place" or generate a new sorted list then copy it over into the given list parameter. You are free to have as many private helper methods as you wish. The compiled Container class is provided as Container.class. The following class diagram shows the relevant members of the Container class: The Container class field called "key" is what you will be using to sort. In other words, an array of Container objects are sorted by their key field. Use getKey () to retrieve this field and use the constructor to set this field. You must have a public class in its own file called Main. This public class will contain the entry point which must do the following: - First generate an array of 20 Container objects, each with a random key ranging from 0 to 150 (inclusively) You will need to look online to figure out how to generate random numbers in a range with Java - Make three exact copies of that array - Send each sorting method its own copy This is so each sorting algorithm can start with the same array contents - Print out the original array of Container objects (only printing the key of each) - Print out the sorted array of Container objects (only printing the key of each) after applying each sorting method See the Sample Output below for more clarification This is used so I can make sure your sorting algorithms work - Now generate an array of 20,000 Container objects each with keys within the same value range as above (i.e. 0 to 150 ) - There will be duplicate keys, but this should not pose a problem for your algorithms - Make three exact copies of this large array - Now use Java to time each algorithm as it runs through its copy of the array You are going to have to look up online how to use Java to get the exact runtime of a block of code It is VERY IMPORTANT that you do NOT include the allocation, initialization or cloning of the array of Container objects in your timing. The only thing I want you to time is the sorting algorithm itself (and maybe the function call to the sorting algorithm). When the algorithm is done (function returns back to main), record the time and move on to timing the next algorithm. - Show the times each algorithm took (in milliseconds) Obviously, we should see Cocktail sort taking the longest amount of time while counting sort takes the least. Quick sort should be somewhat close to the runtime of counting sort. Sample Output: Your output should look exactly like the following (albeit with different numbers for your list and different numbers for your times). Your timings might be different, but they should still be within reason. For example, I expect Cocktail to be in the triple digits, Quick to be in the single digits, and Counting to be the fastest in the low single digits. If your timings do not fall within this range, this is an indication that something is not working right or you aren't timing right. Please ask me for help if you can't figure it out. The spacing, values for n, text, etc must be the same. S javac Main. java \&\& java Main TESTING with n=20 Counting sorted: 024314041435657575867677692117120129138 TIMING with n=20,000 Cocktail took 802.74ms Quick took 4.78ms Counting took 2.49ms

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

A paraphrase is a verbatim restatement of someones message.

Answered: 1 week ago