Invokes the selection sort algorithm to sort them

Assignment Help Data Structure & Algorithms
Reference no: EM131299322

Polymorphic Sorting

In this exercise, you will use the Sorting class to sort several different types of objects.

1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to your directory. Numbers.java won't compile in its current form. Study it to see if you can figure out why.

2. Try to compile Numbers.java and see what the error message is. The problem involves the difference between primitive data and objects. Change the program so it will work correctly (note: you don't need to make many changes the autoboxing feature of Java 1.5 will take care of most conversions from int to Integer).

3. Write a program Strings.java, similar to Numbers.java, that reads in an array of String objects and sorts them. You may just copy and edit Numbers.java.

4. Modify the insertionSort algorithm so that it sorts in descending order rather than ascending order.

Change Numbers.java and Strings.java to call insertionSort rather than selectionSort. Run both to make sure the sorting is correct.

5. The file Salesperson.java partially defines a class that represents a sales person. This is very similar to the Contact class in Listing 9.10. However, a sales person has a first name, last name, and a total number of sales (an int) rather than a first name, last name, and phone number. Complete the compareTo method in the Salesperson class. The comparison should be based on total sales; that is, return a negative number if the executing object has total sales less than the other object and return a positive number if the sales are greater. Use the name of the sales person to break a tie (alphabetical order).

6. The file WeeklyS ales .java contains a driver for testing the compareTo method and the sorting. Compile and run it. Make sure your compareTo method is correct.

The sales staff should be listed in order of sales from most to least with the four people having the same number of sales in reverse alphabetical order.

Reference no: EM131299322

Questions Cloud

Define a competitive equilibirum for this economy : ECON 3102-004 Intermediate Macroeconomics Assignment. Define a Competitive Equilibirum for this economy. Characterize the CE with a system of 9 equations. Clearly state what variables can be pinned down and which cannot
Create the report for the given case study : Given is the Case Study topic is : "Murphy Manufacturing".- Prepare a complete and comprehensive report for Joe to use for his two o'clock meeting.
Direct and indirect effects of an increase : What are the direct and indirect effects of an increase in the money supply? What are the effects of a tariff on a good?
Pursuing a fixed exchange rate regime : Assume that policy makers are pursuing a fixed exchange rate regime. Now suppose that the foreign interest rate increases. Discuss what policy makers must do to maintain the pegged exchange rate. Also discuss what effect this will have on domestic..
Invokes the selection sort algorithm to sort them : The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to your directory.
Equation for the marginal revenue : a. Write down the equation for the marginal revenue b. How many copies of the book would maximize the company's profits? c. What would the profit-maximizing price be? d. How much profit would the company make?
Performance of workers in all the company’s jobs : Does the reason for the policy change involve the reliability, the bias, or the validity of IQ tests as a measure of future job performance? Explain your answer.
Participate in this discussion by explaining : Participate in this discussion by explaining in what ways the firm that owns and operates the Rialto, Colony, and Studio movie theaters appears to be involved in monopolistic competition.
Identify possible sources of suspicious numbers : Are any of the numbers suspect? Why? You might look at the questions in the EESEE story to help you identify possible sources of suspicious numbers.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Write the preorder traversal representation of the tree

Explain your key steps in determining the shortest path, and give the node sequence that corresponds to that shortest path - Write the preorder traversal representation of the tree.

  find the minimum and maximum values in s

Given an array s =(s[1], s[2], . . . , s[n]), and n = 2^d for some d = 1. We want to find the minimum and maximum values in s. We do this by comparing elements of s.

  Explain method for combining two trees-heap-order property

Assume two binary trees, T 1 and T 2 , hold entries satisfying heap-order property. Explain method for combining T 1 and T 2 into a tree T whose internal nodes hold union of entries

  Describe an algorithm to play the game of nim

Describe an algorithm to play the Game of Nim using all of the three tools discussed in class (pseudocode, flowchart, hierarchy chart).

  Evaluate the reliability of the data mining algorithms

the development of complex algorithms that can mine mounds of data that have been collected from people and digital

  Modify the stack example

Modify the stack example so that it stores characters instead of integers.

  Convert the following formulas from reverse polish to infix

Convert the following formulas from reverse Polish to infix.

  How output of leaky bucket policer can be fed in second

Illustrate how output of the leaky bucket policer can be fed into second leaky bucket policer so that two leaky buckets in series police average rate, peak rate, and burst size.

  Store the grades that you read in an arraylist

We expect the file to contain grades represented by integer values, one per line. If you encounter a value that is not an integer, you should throw an exception, print a message to the console, skip that value, and continue processing.

  The development of complex algorithms that can mine mounds

the development of complex algorithms that can mine mounds of data that have been collected from people and digital

  Shell scripting based questions

Determine will the following only print the text "I FOUND A MATCH" to standard output when the grep is successful? if grep "mrichard" /etc/passwd; then echo "I FOUND A MATCH"; fi

  Write a program to simulate the behavior of an array

Write a program to simulate the behavior of an m * n array of two-input NAND gates. This circuit, contained on a chip, has j input pins and k output pins.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd