All code implemented in this assignment should be in a class called Homework3. You may use...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
All code implemented in this assignment should be in a class called Homework3. You may use the data structures and algorithm code from the lecture notes. Define a class Car as follows: class Car { } public String make; public String model; public int mpg; // Miles per gallon. a) (2 points) Implement a comparator called Compare CarsByMake ThenModel that can be passed as an argument to the quicksort method from the lecture notes. Compare CarsByMakeThenModel 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) (2 points) Implement a comparator called Compare Cars By DescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. Compare CarsBy DescendingMPG should return a value that will cause quicksort to sort an array of cars in descending order (from largest to smallest) by mpg. c) (2 points) Implement a comparator called compare CarsByMake Then DescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. Compare CarsByMakeThenDescendingMPG 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) (3 points) 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 } CSE-41321 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. 1 e) (1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, and follows programming best-practices. All code implemented in this assignment should be in a class called Homework3. You may use the data structures and algorithm code from the lecture notes. Define a class Car as follows: class Car { } public String make; public String model; public int mpg; // Miles per gallon. a) (2 points) Implement a comparator called Compare CarsByMake ThenModel that can be passed as an argument to the quicksort method from the lecture notes. Compare CarsByMakeThenModel 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) (2 points) Implement a comparator called Compare Cars By DescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. Compare CarsBy DescendingMPG should return a value that will cause quicksort to sort an array of cars in descending order (from largest to smallest) by mpg. c) (2 points) Implement a comparator called compare CarsByMake Then DescendingMPG that can be passed as an argument to the quicksort method from the lecture notes. Compare CarsByMakeThenDescendingMPG 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) (3 points) 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 } CSE-41321 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. 1 e) (1 point) Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, and follows programming best-practices.
Expert Answer:
Answer rating: 100% (QA)
heres the updated implementation of the Homework3 class with all the required comparators java publi... View the full answer
Related Book For
Posted Date:
Students also viewed these operating system questions
-
then calculates the. 1) Create an M-file (script) that prompts the user to enter a value of x and value of sin (x). 5 pts 2) Create an M-file (script) that prompts the user to enter a matrix and then...
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
An airplane is flying at 32,000 feet when it starts its decent. It is descending at a rate of 2000 feet per minute. Let x represent the minutes of the flight's descent and y represent the planes...
-
The U.S. Treasury attempted to resolve the credit crisis by establishing a plan to buy mortgage-backed securities held by financial institutions. Explain how the plan could improve the situation for...
-
As we hope you agree, there seem to be two kinds of lakes. Two (Pierce and Seminole) have small harvests that dont show a time trend. Th e other three lakes have much bigger harvests that increase...
-
The Decoste Furniture Company has two departments. Data for 2007 include the following: Direct materials (30 types) $65,000 Work-in-process (in assembly) 50,000 Finished goods 40,000 Manufacturing...
-
In the drawing below you can see a cut through a bevel gear box. The torque from the drive side (1) is transmitted with the bevel gear (2) to the outcome side (3). The drawing has some design flaws...
-
. Explain what is meant by the statement cos (0.9) = 25.84.
-
LO 4-6 4.64 Compliance with Laws and Regulations. Audit standards distinguish auditors' responsi- bility for planning procedures for detecting noncompliance with laws and regulations having a direct...
-
a. What types of reports are encompassed by the term special reports as described in SAS 62? b. State a common characteristic of the types of data covered by special reports.
-
a. What evidence is required in an audit of litigation, claims, and assessments? b. What is a letter of audit inquiry? c. What effects may failure of a lawyer to respond to a letter of audit inquiry...
-
a. What objectives are met in obtaining a client representation letter? b. What is the impact of a client's refusal to provide a rep letter.
-
What was Tootsie Roll's largest current asset, largest current liability, and largest item under "Other assets" at December 31, 2007 ?
-
a. Identify the four types of attest engagements that have been recognized in professional standards. b. Indicate the levels of assurance and attestation risk associated with each type.
-
TVA Company produces three products from the same process and incurs joint processing costs of P150,000. Gallons Sales price per gallon at split-off Disposal cost per gallon at split-off Further...
-
Calculate Total Contribution Margin for the same items. Total Revenue Total Variable Costs Total Contribution Margin $50.00 a. $116.00 $329.70 b. $275.00 $14,796.00 $7,440.00 c. $40,931.25 d....
-
According to the American Time Use Survey conducted by the Bureau of Labor Statistics (www.bls.gov/atus/), Americans spent an average of 985.50 hours watching television in 2010. Suppose that the...
-
Refer to Exercise 3.22. The following data represent the number of Grand Jury indictments for Gloucester County, New Jersey, for a sample of 11 weeks selected from July 2010 through June 2011 as...
-
Refer to Exercise 3.24, which listed the number of women from each of 12 countries who were on the Rolex Womens World Golf Rankings Top 50 list as of July 18, 2011. Those data are reproduced here:...
-
What does a high net wells to gross wells ratio indicate?
-
What is the value added ratio? What does a high (low) value added ratio indicate?
-
What does a low average reserves per well ratio indicate?
Study smarter with the SolutionInn App