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 (7th 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 } 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.arrow_forwardThe split method in the String class returns an array of strings consisting of the substrings split by the delimiters. However, the delimiters are not returned. Implement the following new method that returns an array of strings consisting of the substrings split by the matching delimiters, including the matching delimiters. public static String[] split(String s, String regex) For example, split("ab#12#453", "#") returns ab, #, 12, #, and 453 in an array of String and split("a?b?gf#e", "[?#]") returns a, ?, b, ?, gf, #, and e in an array of String.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_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 } 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 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_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 } 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_forward
- Complete the implementation of scrabble.c, such that it determines the winner of a short scrabble-like game, where two players each enter their word, and the higher scoring player wins. Notice that we’ve stored the point values of each letter of the alphabet in an integer array named POINTS. For example, A or a is worth 1 point (represented by POINTS[0]), B or b is worth 3 points (represented by POINTS[1]), etc. Notice that we’ve created a prototype for a helper function called compute_score() that takes a string as input and returns an int. Whenever we would like to assign point values to a particular word, we can call this function. Note that this prototype is required for C to know that compute_score() exists later in the program. In main(), the program prompts the two players for their words using the get_string() function. These values are stored inside variables named word1 and word2. In compute_score(), your program should compute, using the POINTS array, and return the score…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_forwardWrite a class that represents a player in a game. The player should have a name, password,experience points, an inventory array of four strings, and a location x,y. Your class shouldhave mutator and accessor methods for all variables. For example: setName(), getName(). Itshould have a suitable display method. Mutators and accessors should be public but allvariables should be private. To implement get inventory, use string * getInv(); Use the scoperesolution operator to implement larger methods such as display(). Use in class methods forshorter methods such as setName(), getName(). (in C++)Example:void setName(string name){this->name = name;}string *getInv();...string* player::getInv(){return inventory;}Note that in the above method setName “this->” is required for disambiguation. If writtenvoid setName(string n){name = n;}“this->” is not required.Write a test program that creates three players and displays them.Example Output:This program generates three player objects and…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_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