Description of this paper





;;CSE 1302 J;Fall 2011;Lab 5;Polymorphism;Objective ? to study polymorphism;Complete all steps;Extra Instructions;Turn in and and the outputs from each, using descending order with the insertion sort (Step 4).;Turn in and output from (Step 6). The instructions are a little confusing but I want the output to be in descending order on total sales and ascending order for the names within the same total sales bracket. That means;?. 4935;Black, Jane 3000;Jones, James 3000;Jones, Jane 3000;Smith, Walt 3000;?. 2850;Polymorphic Sorting;The file contains the Sorting class. 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. Notice that the one sort method can be used to sort an array of Integers, an array of Strings, and an array of SalesPerson objects.;The file reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save and to your directory. won't compile in its current form. Study it to see if you can figure out why.;Try to compile 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).;Write a program, similar to, that reads in an array of String objects and sorts them. You may just copy and edit;Modify the insertionSort algorithm so that it sorts in descending order rather than ascending order. Change and to call insertionSort rather than selectionSort. Run both to make sure the sorting is correct. These are the runs you should turn in from and;The file partially defines a class that represents a sales person. A sales person has a first name, last name, and a total number of sales (an int). 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).;The file contains a driver for testing the compareTo method and the sorting. Compile and run it. Make sure your compareTo method is correct. See sample output given above. The sales staff should be listed in order of sales from most to least (descending) with the four people having the same number of sales in ascending alphabetical order.;//********************************************************************;// Author: Lewis/Loftus;//;// Demonstrates the selection sort and insertion sort algorithms.;//********************************************************************;public class Sorting;//-----------------------------------------------------------------;// Sorts the specified array of objects using the selection;// sort algorithm.;//-----------------------------------------------------------------;public static void selectionSort (Comparable[] list);int min;Comparable temp;for (int index = 0, index < list.length-1, index++);min = index;for (int scan = index+1, scan < list.length, scan++);if (list[scan].compareTo(list[min]) < 0);min = scan;// Swap the values;temp = list[min];list[min] = list[index];list[index] = temp;//-----------------------------------------------------------------;// Sorts the specified array of objects using the insertion;// sort algorithm.;//-----------------------------------------------------------------;public static void insertionSort (Comparable[] list);for (int index = 1, index 0 && key.compareTo(list[position-1]) < 0);list[position] = list[position-1];position--;list[position] = key;// ******************************************************;//;//;// Demonstrates selectionSort on an array of integers.;// ******************************************************;import java.util.Scanner;public class Numbers;// --------------------------------------------;// Reads in an array of integers, sorts them;// then prints them in sorted order.;// --------------------------------------------;public static void main (String[] args);int[] intList;int size;Scanner scan = new Scanner(;System.out.print ("\nHow many integers do you want to sort? ");size = scan.nextInt();intList = new int[size];System.out.println ("\nEnter the numbers...");for (int i = 0, i < size, i++);intList[i] = scan.nextInt();Sorting.selectionSort(intList);System.out.println ("\nYour numbers in sorted order...");for (int i = 0, i < size, i++);System.out.print(intList[i] + " ");System.out.println ();// *******************************************************;//;//;// Represents a sales person who has a first name, last;// name, and total number of sales.;// *******************************************************;public class Salesperson implements Comparable;private String firstName, lastName;private int totalSales;//------------------------------------------------------;// Constructor: Sets up the sales person object with;// the given data.;//------------------------------------------------------;public Salesperson (String first, String last, int sales);firstName = first;lastName = last;totalSales = sales;//-------------------------------------------;// Returns the sales person as a string.;//-------------------------------------------;public String toString();return lastName + ", " + firstName + ": \t" + totalSales;//-------------------------------------------;// Returns true if the sales people have;// the same name.;//-------------------------------------------;public boolean equals (Object other);return (lastName.equals(((Salesperson)other).getLastName());firstName.equals(((Salesperson)other).getFirstName()));//--------------------------------------------------;// Order is based on total sales with the name;// (last, then first) breaking a tie.;//--------------------------------------------------;public int compareTo(Object other);int result;return result;//-------------------------;// First name accessor.;//-------------------------;public String getFirstName();return firstName;//-------------------------;// Last name accessor.;//-------------------------;public String getLastName();return lastName;//-------------------------;// Total sales accessor.;//-------------------------;public int getSales();return totalSales;// *************************************************************;//;//;// Sorts the sales staff in descending order by sales.;// ************************************************************;public class WeeklySales;public static void main(String[] args);Salesperson[] salesStaff = new Salesperson[10];salesStaff[0] = new Salesperson("Jane", "Jones", 3000);salesStaff[1] = new Salesperson("Daffy", "Duck", 4935);salesStaff[2] = new Salesperson("James", "Jones", 3000);salesStaff[3] = new Salesperson("Dick", "Walter", 2800);salesStaff[4] = new Salesperson("Don", "Trump", 1570);salesStaff[5] = new Salesperson("Jane", "Black", 3000);salesStaff[6] = new Salesperson("Harry", "Taylor", 7300);salesStaff[7] = new Salesperson("Andy", "Adams", 5000);salesStaff[8] = new Salesperson("Jim", "Doe", 2850);salesStaff[9] = new Salesperson("Walt", "Smith", 3000);Sorting.insertionSort(salesStaff);System.out.println ("\nRanking of Sales for the Week\n");for (Salesperson s: salesStaff);System.out.println (s)


Paper#65396 | Written in 18-Jul-2015

Price : $37