Please complete the task by yourself only in JAVA with explanation. Don't copy. Thank you. Only finish the (d) question, 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 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. d) Write a main method that tests your methods from parts a-c with the following array of cars: Car cars[] = { { "Toyota", "Camry", 33 }, { "Ford", "Focus", 40 }, { "Honda", "Accord", 34 }, { "Ford", "Mustang", 31 }, { "Honda", "Civic", 39 }, { "Toyota", "Prius", 48 }, { "Honda", "Fit", 35 }, { "Toyota", "Corolla", 35 }, { "Ford", "Taurus", 28 } } Your test program should do the following: 1. Output (displaying make, model, and MPG) the cars in original unsorted order. 2. Output the cars sorted (using qksort from the book) by make then model. 3. Output the cars sorted (using qksort from the book) by descending MPG. 4. Output the cars sorted (using qksort from the book) by make then descending MPG.
Please complete the task by yourself only in JAVA with explanation. Don't copy. Thank you.
Only finish the (d) question, 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 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.
d) Write a main method that tests your methods from parts a-c with the following
array of cars:
Car cars[] = {
{ "Toyota", "Camry", 33 },
{ "Ford", "Focus", 40 },
{ "Honda", "Accord", 34 },
{ "Ford", "Mustang", 31 },
{ "Honda", "Civic", 39 },
{ "Toyota", "Prius", 48 },
{ "Honda", "Fit", 35 },
{ "Toyota", "Corolla", 35 },
{ "Ford", "Taurus", 28 }
}
Your test program should do the following:
1. Output (displaying make, model, and MPG) the cars in original unsorted order.
2. Output the cars sorted (using qksort from the book) by make then model.
3. Output the cars sorted (using qksort from the book) by descending MPG.
4. Output the cars sorted (using qksort from the book) by make then descending MPG.
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)