Revise the method selectionSort within the class ArraySorter, as shown in Listing 7.10 of Chapter 7, so that it sorts the strings in an instance of the class ArrayList<String> into lexicographic order instead of sorting the integers in an array into ascending order. For words, lexicographic order reduces to alphabetic order if all the words are in either lowercase or uppercase letters. You can compare two strings to see which is lexicographically first by using the String method compareTo, as described in Figure 2.5 of Chapter 2.
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Additional Engineering Textbook Solutions
C Programming Language
Starting Out with Java: From Control Structures through Objects (6th Edition)
Starting Out With Visual Basic (7th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Please complete the task by yourself only in JAVA with explanation. Don't copy. Thank you. Using quicksort to sort an array of car objects by various criteria. Define a class Car as follows: class Car { public String make; public String model; public int mpg; // Miles per gallon } a) Implement a comparator called CompareCarsByMakeThenModel that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByMakeThenModel should return a value that will cause quicksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model. b) Implement a comparator called CompareCarsByDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByDescendingMPG should return a value that will cause quicksort to sort an array of cars in descending order (from largest to smallest) by mpg. c) Implement a comparator called…arrow_forwardPlease complete the task by yourself only in JAVA with explanation. Don't copy. Thank you. Using quicksort to sort an array of car objects by various criteria. Define a class Car as follows: class Car { public String make; public String model; public int mpg; // Miles per gallon } a) Implement a comparator called CompareCarsByMakeThenModel that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByMakeThenModel should return a value that will cause quicksort to sort an array of cars in ascending order (from smallest to largest) by make and, when two cars have the same make, in ascending order by model.arrow_forwardPlease use java. In this assignment, you will implement a class calledArrayAndArrayList. This class includes some interesting methods for working with Arrays and ArrayLists. For example, the ArrayAndArrayList class has a “findMax” method which finds and returns the max number in a given array. For a defined array: int[] array = {1, 3, 5, 7, 9}, calling findMax(array) will return 9. There are 4 methods that need to be implemented in the A rrayAndArrayList class: ● howMany(int[] array, int element) - Counts the number of occurrences of the given element in the given array. ● findMax(int[] array) - Finds the max number in the given array. ● maxArray(int[] array) - Keeps track of every occurrence of the max number in the given array. ● swapZero(int[] array) - Puts all of the zeros in the given array, at the end of the given array. Each method has been defined for you, but without the code. See the javadoc for each method for instructions on what the method is supposed to do and how…arrow_forward
- Please complete the task by yourself only in JAVA with explanation. Don't copy. Thank you. Using quicksort to sort an array of car objects by various criteria. Define a class Car as follows: class Car { public String make; public String model; public int mpg; // Miles per gallon } c) Implement a comparator called CompareCarsByMakeThenDescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. CompareCarsByMakeThenDescendingMPG should return a value that will cause quicksort to sort an array of cars in ascending order by make and, when two cars have the same make, in descending order by mpg.arrow_forwardhow would you do this in a simple way? this is a non graded practice labarrow_forwardPLease use java In this assignment, you will implement a class called ArrayAndArrayList. This class includessome interesting methods for working with Arrays and ArrayLists.For example, the ArrayAndArrayList class has a “findMax” method which finds and returns themax number in a given array. For a defined array: int[] array = {1, 3, 5, 7, 9}, callingfindMax(array) will return 9.There are 4 methods that need to be implemented in the ArrayAndArrayList class:● howMany(int[] array, int element) - Counts the number of occurrences of the givenelement in the given array.● findMax(int[] array) - Finds the max number in the given array.● maxArray(int[] array) - Keeps track of every occurrence of the max number in the givenarray.● swapZero(int[] array) - Puts all of the zeros in the given array, at the end of the givenarray.Each method has been defined for you, but without the code. See the javadoc for each methodfor instructions on what the method is supposed to do and how to write the code. It…arrow_forward
- Using JAVA, write a method that modifies an ArrayList<String>, moving all strings starting with an uppercase letter to the front, without otherwise changing the order of the elements. Write a test program to demonstrate the correct operation of the method.arrow_forwardCODe full java. In this assignment, you will implement a class called ArrayAndArrayList. This class includessome interesting methods for working with Arrays and ArrayLists.For example, the ArrayAndArrayList class has a “findMax” method which finds and returns themax number in a given array. For a defined array: int[] array = {1, 3, 5, 7, 9}, callingfindMax(array) will return 9.There are 4 methods that need to be implemented in the ArrayAndArrayList class:● howMany(int[] array, int element) - Counts the number of occurrences of the givenelement in the given array.● findMax(int[] array) - Finds the max number in the given array.● maxArray(int[] array) - Keeps track of every occurrence of the max number in the givenarray.● swapZero(int[] array) - Puts all of the zeros in the given array, at the end of the givenarray.Each method has been defined for you, but without the code. See the javadoc for each methodfor instructions on what the method is supposed to do and how to write the code. It…arrow_forwardwrite a program using java Write the class Student having attributes Id (int), name (String), age (int) and cgpa (double) and methods to set the values of attributes and to return them.Write another class name Student Management having array of students and count of students as attribute. There should be method for the following:1. Add new Student in Array2. Remove a Student from Array using Id (of Student)3. Sort the Students in array using Id (ascending order)4. Sort the Students in array using Age (ascending order)5. Sort the Students in array using CGPA (ascending order)6. Reverse the order of the Students in array7. Display information of all Students in array (from zero index to last index)Write another class named as Main having main method and show activity of above methods.1. Add 5 Students in array2. Display all students in array3. Remove a student by name [Hint: Use equals method to check equality e.g. str1.equals(str2) ]4. Display all student in array5. Sort array by Id and…arrow_forward
- I have an ArrayList and I want to sort it by increasing string length. The ArrayList class has a method sort(Comparator comp). Give a class that implements the Comparator interface that I can use to sort my ArrayList.arrow_forwardImprove the method printList to print out the details of all publications ordered on the category of the publications, and then on the title within each category. Note: currently there are only 2 categories, i.e. Book and Journal, but the project may be expended by adding other categories, e.g. Newspaper etc. Here are my four classes. public class Database {private ArrayList<Publication> publicationList; // An array list collection of publications /*** Create a new database*/public Database() {publicationList = new ArrayList<Publication>();} /*** Add a publication** @param publication The publication to be added*/public void addPublication(Publication publication) {if (publicationList.contains(publication)) {System.out.println("This publication has already been added to the list: " + publication);} else {publicationList.add(publication);}} /*** Get the total number of publications** @return The total number of publications*/public int getTotal() {return…arrow_forward5. Write a static method largestColumnFirst() that receives as parameter a 2D array numAr,finds the column with the largest sum, and switches it with the first column. For example:6 7 9 4 8 9 7 6 4 83 2 7 4 1 → 7 2 3 4 19 4 5 8 3 5 4 9 8 3arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education