Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The file Sorting.java contains the Sorting class from lecture slides. This class implements both the selection sort and the insertion sort algorithms for sorting any

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The file Sorting.java contains the Sorting class from lecture slides. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects l. 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 Sortingjava and Numbersjava to your directory. Numbersjava won't compile in its current form. Study it to see if you can figure out why. Hint: Wrapper class of int 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 when scan in data from keyboard) 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 Numbersjava and Stringsjava to call insertionsort rather than selectionsort. Run both to make sure the sorting is correct. 5. The file Salespersonjava partially defines a class that represents a sales person. This is very similar to the Contact class in our lecture. 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 Weekly Sales java contains a driver for testing the compareTo method and the sorting Compile and run it. Make sure your compare To 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. 7. OPTIONAL: Modify WeeklySalesjava so the salespeople are read in rather than hardcoded in the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions