you are required to implement the quick sort algorithm for sections of students, and a method...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
you are required to implement the quick sort algorithm for sections of students, and a method that verifies if a given tree array represents a heap. You are provided with two class files: Student.java and Section.java. For simplicity, each student has only two attributes: ID and GPA. A student can be presented as a string consisting of their ID and GPA. A student can be presented as a string consisting of their ID and GPA. For example, a student with an ID of 33251 and a GPA of 3.44 can be presented as "33251 (3.44)". Students are sorted in ascending order based on their GPA (students with a lower GPA are placed in front of those with a higher GPA). If two students have the same GPA, then the one with the lower ID should show up before the one with the higher ID. To compare two students, you need to compare their GPAS first, and then their IDs. Here are some examples: Student 33251(3.44) is smaller than student 42641 (3.95) because 3.44 is lower than 3.95. Student 19832(2.93) is greater than student 29831(2.87) because 2.93 is higher than 2.87. Student 29753(3.07) is greater than student 13528(3.07) because although their GPAs are identical, the first student has a higher ID than the second student. For the homework, you are provided with two additional files: Homework.java and TestHomework.java. You are required to complete the following methods in Homework: ☐int compares (Student s1, Student s2) This method takes two student objects and returns -1, 0, or 1 if s1 is smaller, equal to, or greater than s2, respectively. You need to compare their GPAs first and if they have the same GPA, then compare their IDs. void quickSort (Student[] studentArray, int first, int last) This method takes a student array as well as two indices. It sorts the students in the range specified by first and last with quick sort. It first calls the split method to partition the elements in the range into two subarrays, and sorts both subarrays recursively. It repeats this process until the entire array is sorted. int split (Student[] studentArray, int first, int last) This is a helper method for quick sort which takes a student array and two indices. It begins by selecting the first element in the student array as the pivot, and then moves elements so that everything in the left subarray is smaller than the pivot and everything on the right is greater than the pivot. The method returns the final index of the pivot. You are required to call the compares method to make comparisons between students. boolean isHeap(int[] A) This method takes an int array as the parameter and verifies if the elements saved in this array form a heap. You can assume that the array represents a complete binary tree so the shape property is already satisfied. You will need to verify that the elements meet the order property requirement for heaps. Return true if this is a heap, false otherwise. This method is separate from the above methods and has nothing to do with the Student or Section classes used by other methods. Test your code: You are provided with a test driver implemented in "TestHomework.java" (do not make any changes to this file!) so there is no need to write your own testing code. You are also given a data file "Sections.dat" that contains five pre-generated test sections as well as the sorted arrays. Each section has different numbers of students, so your program should work for any size section. (Note: you may need to move your data file for your IDE to be able to read it. For jGRASP, you can leave the data file in the same folder as your java files. For IntelliJ, you should place it in your project folder in which you see directories like out and src, etc.) Once you have completed the above classes, you can run the test. You should create a plain text file named "output.txt", copy and paste the output (if your code crashes or does not compile, copy and paste the error messages) this file and save it. Grading Rubric: Code does not compile: -10 Code compiles but crashes when executed: -5 ☐ Changes were made outside the required methods: -5 Has output file: 6 compares was correctly implemented: 5 ☐ quickSortRec was correctly implemented: 5 split was correctly implemented: 10 isHeap was correctly implemented: 10 ☐passes 8 test cases (3 pts each): 24 Sample Output: Test 1: quickSort() ==> [Passed] Original Section: [32336(2.68), 15739 (3.69), 34065 (2.98), 27165(3.31), 28179 (2.27), 11933(2.98), 35508 (3.34), 30209 (2.19), 24768 (2.58), 23015 (3.63), 37109 (3.1), 33453 (2.68), 15254 (3.31), 32899 (2.98)] Expected Section: [30209 (2.19), 28179(2.27), 24768 (2.58), 32336(2.68), 33453 (2.68), 11933(2.98), 32899(2.98), 34065 (2.98), 37109 (3.1), 15254 (3.31), 27165 (3.31), 35508 (3.34), 23015 (3.63), 15739 (3.69)] Yours: [30209 (2.19), 28179(2.27), 24768 (2.58), 32336(2.68), 33453(2.68), 11933 (2.98), 32899(2.98), 34065(2.98), 37109 (3.1), 15254(3.31), 27165(3.31), 35508 (3.34), 23015 (3.63), 15739(3.69)] Test 2: quickSort() ==> [Passed] Original Section: [13042 (3.13), 23394(2.65), 36600(2.18), 15075 (2.06),14479(3.13), 32135 (3.72), 22517(3.01), 17913(2.06)] Expected Section: [15075 (2.06), 17913(2.06), 36600 (2.18), 23394(2.65), 22517 (3.01), 13042 (3.13), 14479(3.13), 32135(3.72)] Yours: [15075 (2.06), 17913(2.06), 36600 (2.18), 23394 (2.65), 22517(3.01), 13042 (3.13), 14479 (3.13), 32135(3.72)] Test 7: isHeap ([50, 43, 27, 35, 44, 15, 22, 20]) ==> [Passed] Expected: false Yours: false Test 8: isHeap ([32, 27, 30, 19, 16, 21, 3, 10, 2, 4]) ==> [Passed] Expected: true Yours: true Total test cases: 8 Correct: 8 Wrong: 0 3/.../ 2 usages public class Homework { 3 J 3 1 // student comparison no usages public int compares (Student s1, Student s2) { } // TODO: implement this method return -1; // replace this statement with your own return // This is the wrapper method for quick sort // Do not make any changes to this method! 1 usage public void quickSort(Student[] studentArray) { quickSortRec (studentArray, first: 0, last: studentArray.length A 11 ^ V // This is the recursive helper method for quickSort that sorts the students based on their GPAS in // increasing order. // Note: If two students have the same GPA, then the one with lower student ID should show up in front of // the one with higher ID. 1 usage public void quickSortRec (Student[] studentArray, int first, int last) { // TODO: implement this method // This method splits a Student array into two sections, with all the elements less than the pivot in the // left section and all the elements greater than the pivot in the right section no usages public int split(Student[] studentArray, int first, int last) - 1); H H // This method splits a Student array into two sections, with all the elements less than the pivot in the // left section and all the elements greater than the pivot in the right section no usages public int split (Student[] studentArray, int first, int last) { } // TODO: implement this method @ } return -1; // replace this statement with your own return // This method takes an int array which represents a complete binary tree as // the parameter. It checks if the tree stored in the array is a heap. 3 usages public boolean isHeap (int[] A) { // TODO: implement this method return false; // replace this statement with your own return you are required to implement the quick sort algorithm for sections of students, and a method that verifies if a given tree array represents a heap. You are provided with two class files: Student.java and Section.java. For simplicity, each student has only two attributes: ID and GPA. A student can be presented as a string consisting of their ID and GPA. A student can be presented as a string consisting of their ID and GPA. For example, a student with an ID of 33251 and a GPA of 3.44 can be presented as "33251 (3.44)". Students are sorted in ascending order based on their GPA (students with a lower GPA are placed in front of those with a higher GPA). If two students have the same GPA, then the one with the lower ID should show up before the one with the higher ID. To compare two students, you need to compare their GPAS first, and then their IDs. Here are some examples: Student 33251(3.44) is smaller than student 42641 (3.95) because 3.44 is lower than 3.95. Student 19832(2.93) is greater than student 29831(2.87) because 2.93 is higher than 2.87. Student 29753(3.07) is greater than student 13528(3.07) because although their GPAs are identical, the first student has a higher ID than the second student. For the homework, you are provided with two additional files: Homework.java and TestHomework.java. You are required to complete the following methods in Homework: ☐int compares (Student s1, Student s2) This method takes two student objects and returns -1, 0, or 1 if s1 is smaller, equal to, or greater than s2, respectively. You need to compare their GPAs first and if they have the same GPA, then compare their IDs. void quickSort (Student[] studentArray, int first, int last) This method takes a student array as well as two indices. It sorts the students in the range specified by first and last with quick sort. It first calls the split method to partition the elements in the range into two subarrays, and sorts both subarrays recursively. It repeats this process until the entire array is sorted. int split (Student[] studentArray, int first, int last) This is a helper method for quick sort which takes a student array and two indices. It begins by selecting the first element in the student array as the pivot, and then moves elements so that everything in the left subarray is smaller than the pivot and everything on the right is greater than the pivot. The method returns the final index of the pivot. You are required to call the compares method to make comparisons between students. boolean isHeap(int[] A) This method takes an int array as the parameter and verifies if the elements saved in this array form a heap. You can assume that the array represents a complete binary tree so the shape property is already satisfied. You will need to verify that the elements meet the order property requirement for heaps. Return true if this is a heap, false otherwise. This method is separate from the above methods and has nothing to do with the Student or Section classes used by other methods. Test your code: You are provided with a test driver implemented in "TestHomework.java" (do not make any changes to this file!) so there is no need to write your own testing code. You are also given a data file "Sections.dat" that contains five pre-generated test sections as well as the sorted arrays. Each section has different numbers of students, so your program should work for any size section. (Note: you may need to move your data file for your IDE to be able to read it. For jGRASP, you can leave the data file in the same folder as your java files. For IntelliJ, you should place it in your project folder in which you see directories like out and src, etc.) Once you have completed the above classes, you can run the test. You should create a plain text file named "output.txt", copy and paste the output (if your code crashes or does not compile, copy and paste the error messages) this file and save it. Grading Rubric: Code does not compile: -10 Code compiles but crashes when executed: -5 ☐ Changes were made outside the required methods: -5 Has output file: 6 compares was correctly implemented: 5 ☐ quickSortRec was correctly implemented: 5 split was correctly implemented: 10 isHeap was correctly implemented: 10 ☐passes 8 test cases (3 pts each): 24 Sample Output: Test 1: quickSort() ==> [Passed] Original Section: [32336(2.68), 15739 (3.69), 34065 (2.98), 27165(3.31), 28179 (2.27), 11933(2.98), 35508 (3.34), 30209 (2.19), 24768 (2.58), 23015 (3.63), 37109 (3.1), 33453 (2.68), 15254 (3.31), 32899 (2.98)] Expected Section: [30209 (2.19), 28179(2.27), 24768 (2.58), 32336(2.68), 33453 (2.68), 11933(2.98), 32899(2.98), 34065 (2.98), 37109 (3.1), 15254 (3.31), 27165 (3.31), 35508 (3.34), 23015 (3.63), 15739 (3.69)] Yours: [30209 (2.19), 28179(2.27), 24768 (2.58), 32336(2.68), 33453(2.68), 11933 (2.98), 32899(2.98), 34065(2.98), 37109 (3.1), 15254(3.31), 27165(3.31), 35508 (3.34), 23015 (3.63), 15739(3.69)] Test 2: quickSort() ==> [Passed] Original Section: [13042 (3.13), 23394(2.65), 36600(2.18), 15075 (2.06),14479(3.13), 32135 (3.72), 22517(3.01), 17913(2.06)] Expected Section: [15075 (2.06), 17913(2.06), 36600 (2.18), 23394(2.65), 22517 (3.01), 13042 (3.13), 14479(3.13), 32135(3.72)] Yours: [15075 (2.06), 17913(2.06), 36600 (2.18), 23394 (2.65), 22517(3.01), 13042 (3.13), 14479 (3.13), 32135(3.72)] Test 7: isHeap ([50, 43, 27, 35, 44, 15, 22, 20]) ==> [Passed] Expected: false Yours: false Test 8: isHeap ([32, 27, 30, 19, 16, 21, 3, 10, 2, 4]) ==> [Passed] Expected: true Yours: true Total test cases: 8 Correct: 8 Wrong: 0 3/.../ 2 usages public class Homework { 3 J 3 1 // student comparison no usages public int compares (Student s1, Student s2) { } // TODO: implement this method return -1; // replace this statement with your own return // This is the wrapper method for quick sort // Do not make any changes to this method! 1 usage public void quickSort(Student[] studentArray) { quickSortRec (studentArray, first: 0, last: studentArray.length A 11 ^ V // This is the recursive helper method for quickSort that sorts the students based on their GPAS in // increasing order. // Note: If two students have the same GPA, then the one with lower student ID should show up in front of // the one with higher ID. 1 usage public void quickSortRec (Student[] studentArray, int first, int last) { // TODO: implement this method // This method splits a Student array into two sections, with all the elements less than the pivot in the // left section and all the elements greater than the pivot in the right section no usages public int split(Student[] studentArray, int first, int last) - 1); H H // This method splits a Student array into two sections, with all the elements less than the pivot in the // left section and all the elements greater than the pivot in the right section no usages public int split (Student[] studentArray, int first, int last) { } // TODO: implement this method @ } return -1; // replace this statement with your own return // This method takes an int array which represents a complete binary tree as // the parameter. It checks if the tree stored in the array is a heap. 3 usages public boolean isHeap (int[] A) { // TODO: implement this method return false; // replace this statement with your own return
Expert Answer:
Answer rating: 100% (QA)
Given is the programming for Java import javautilScanner public class QuickSort public static void m... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Consider the given vector field. F(x, y, z) = (x + yz)i + (y + xz)j + (z + xy)k (a) Find the curl of the vector field. curl F = (b) Find the divergence of the vector field. div F =
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Suppose a town concludes that it costs on average $30.00 per household to manage the disposal of the waste generated by households each year. It is debating two strategies for funding this cost: (1)...
-
Bar AC supports two 100-lb loads as shown. Rollers A and C rest against frictionless surfaces and a cable BD is attached at B. Determine (a) The tension in cable BD, (b) The reaction at A, (c) The...
-
(a) Give an example of a random experiment, where the number of members in the sample space is 3. (b) Using Venn diagram show that (AUB) = AC B, where AC = complement of A. (c) Give a combinatorial...
-
Discuss the underlying attributes necessary to support high achievers.
-
The popularity of Southwestern University's football program under its new coach Phil Flamm surged in each of the 5 years since his arrival at the Stephenville, Texas, college. (See Southwestern...
-
A block of mass m = 2.50 kg is pushed d = 2.40 m along a frictionless horizontal table by a constant applied force of magnitude F = 18.0 N directed at an angle = 25.0 below the horizontal as shown in...
-
The following table summarizes the operating results for Bene Petits first year of operations: Bene Petit First year operating data: Single (1 serving) Dual (2 servings) Family (4 servings) Total...
-
Your firm would like to evaluate a proposed new operating division. You have forecasted cash flows for this division for the next five years, and have estimated that the cost of capital is 11%. You...
-
This case is really three separate cases, each one adding a new twist to the life and times of Scranton Bank and Trust, a small banking firm in Scranton, Pennsylvania. In the first case, Norwalk Auto...
-
P&F Construction Corporation ordered 338 door units for an apartment condominium project from Friend Lumber Corporation. The doors were delivered to the job site three weeks after they were ordered....
-
What is the difference between the public interest and public policy?
-
Banks in New Transylvania have a desired reserve ratio of 10 percent of deposits and no unplanned reserves. The currency drain ratio is 50 percent of deposits. Now suppose that the central bank...
-
How will the outcomes in the loanable funds market differ if Indias government budget deficit is 3.8 percent or 7 percent of GDP? Indias government budget deficit is 4.6 percent of GDP in 20192020....
-
Astronauts on our moon must function with an acceleration due togravity of 0.165g . Part A If an astronaut can throw a certainwrench 15.0 m vertically upward on earth, how high could he throwit on...
-
The graph of the sequence whose general term is an = n - 1 is which of the following? [8.1] A. B. TITTT 3-2-1 23.45 2.3.4
-
Write a JavaFX program that moves an image toward the location of the mouse. The image shouldnt jump directly to the mouse coordinates (which is what happens in Listing 9.16) but should move a few...
-
Create the classes RightTriangle and Rectangle, each of which is derived from the abstract class ShapeBase in Listing 8.19. Then derive a class Square from the class Rectangle. Each of these three...
-
Suppose that you have a number x that is greater than 1. Write an algorithm that computes the largest integer k such that 2 is less than or equal to x.
-
What is the activity in \(\mathrm{Bq}\) and in \(\mathrm{Ci}\) of a \(2.0 \mathrm{mg}\) sample of \({ }^{3} \mathrm{H}\) ?
-
The activity of a sample of the cesium isotope \({ }^{137} \mathrm{Cs}\) is \(2.0 \times 10^{8} \mathrm{~Bq}\). Many years later, after the sample has fully decayed, how many beta particles will have...
-
The technique known as potassiumargon dating is used to date volcanic rock and ash, and thus establish dates for nearby fossils, like this 1.8 -millionyear-old hominid skull. The potassium isotope...
Study smarter with the SolutionInn App