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
-
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...
-
Do you think that the U.S. financial system will be able to avoid a credit crisis like this in the future?
-
Assume that all of the facts in Problem 5 remain unchanged except that Green paid $201,000 for 60% of the voting shares of Mansford. Required: (a) Prepare a consolidated balance sheet at January 1,...
-
a. Consider the regression using three explanatory variables, FERTILITY, PUBLICEDUCATION, and LNHEALTH that you did in Exercise 3.3.6. Test whether PUBLICEDUCATION and LNHEALTH are jointly...
-
Wolverine Corp. currently has no existing business in New Zealand but is considering establishing a subsidiary there. The following information has been gathered to assess this project: The initial...
-
Calculate the loan risk associated with a $3 million, five-year loan to a BBB-rated corporation in the computer parts industry that has a duration of 3.5 years. The cost of funds for the bank is 8...
-
Open the Orders Solution.sln file contained in the VB2017\Chap03\Orders Solution folder. The interface provides a button for adding the number ordered to the total ordered, and a button for...
-
Before Adjustment Equipment Accumulated Depreciation, Equipment Depreciation Expense, Equipment 10,600 500 Given: At year end, depreciation on Equipment is $ 1 comma 300. Read the requirements. a....
-
Repeat exercise 12.1, but now use for the domestic utility function, and a corresponding expression for the foreign utility function. (a) What are the maximum consumption levels for z and z f ? (b)...
-
Describe the price-fixing scheme as the equilibrium outcome of an oligopoly cartel game played by the airlines. Explain why the cartel survived. To date, 21 airlines have coughed up more than $1.7...
-
Not only has scouring the Web for the best possible price become standard protocol before buying a big-ticket item, but more consumers are employing creative strategies for scoring hot deals....
-
How will the use of robots change the value of marginal product of farm workers? Commercial farms of the future may be staffed by robots that will identify, spray, and pick individual pieces of...
-
What are the main characteristics of people who earn large incomes and who earn small incomes?
-
Krauth Company purchased a machine for $119,000. The machine has a life of seven years with no salvage value. It is expected that the machine will generate annual net cash inflows of $28,000 per year...
-
What do you think?
-
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:...
-
Describe the role of a paralegal in a family law practice.
-
Define family law and identify the kinds of issues that are addressed in a family law practice.
-
Describe the characteristics of effective fee agreements, and identify the various types of fee agreements that may be used in divorce cases.
Study smarter with the SolutionInn App