Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92053970
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Carbonated drinks like cola tonic water and club soda are

Carbonated drinks like cola, tonic water and club soda are pleasantly bubbly due to the following decomposition of carbonic acid: H2CO3(aq) → H2O(l) + CO2(g) If a sample of H2CO3 decomposes over water at 50°C, 0.23 L of ...

Question a security system is used to monitor doors and

Question : A security system is used to monitor doors and windows of a residence. This system uses several components, including photodiodes and contact switches to detect intruders. Circuits associated with contact swit ...

Suppose i am designing a personnel database for a

Suppose I am designing a personnel database for a university. The university has three types of personnel: students, staff, and faculty. Here are the characteristics of the three groups: -All three groups have a name and ...

Explain why a u s recession that occurs as the rest of the

Explain why a U. S. recession that occurs as the rest of the world is expanding will tend to reduce the U. S. Trade deficit.

The probability of a potential employee passing a training

The probability of a potential employee passing a training course is 86%. If you selected 15 potential employees and gave them the training course, what is the probability that more than 12 will pass the test?

Suppose that a large integer k is represented in twos

Suppose that a large integer k is represented in two's complement form. It may be negative, zero, or positive. We say that k is even if and only if |k| mod 2 = 0. How can we quickly test if k is even without using arithm ...

Question erd assignmentcreate a crows foot erd following

Question: ERD Assignment Create a Crow's foot ERD following the business rules for the ProdCo Company. 1. Each sales representative writes many invoices 2. Each invoice is written by one sales representative 3. Each sale ...

Can you give me short cut of using excel word access share

Can you give me short cut of using excel, word, access, share point, and powerpoint microsoft, I am always have to rely on the back and forth, fleepng the pages, it is possible

A professor collected data on the number of absences in an

A professor collected data on the number of absences in an introductory statistics class of 100 students over the course of a semester. The data are summarized below. Number of Absences 0 1 2 3 4 5 6 Number of Students 5 ...

A study was conducted of long beach school district schools

A study was conducted of Long Beach School District schools regarding how many require school uniforms. In 2006, of the 296 schools questioned, 184 said they required s school uniforms. (Gentile & Imberman, 2009) Find th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As