Question: Java (Please Follow Instructions) (Needed Code is Provided) Add a method that will Sort the data in your Array of Objects. Write your code from

Java (Please Follow Instructions) (Needed Code is Provided)

  1. Add a method that will Sort the data in your Array of Objects.
    1. Write your code from the Selection Sort algorithm in the lecture.
    2. Pick one default field to sort the data by.
  2. Display a menu that will allow the User to select at least one other field to sort the data by.
  3. DO NOT use any of Java's built-in sorting methods. YOU MUST write your own using the Selection Sort algorithm discussed in the lecture.

C. Be sure to also include the following:

  • Create a Driver Class with a Menu with the following options displayed like so:
    1. Add an item to the array.
    2. Update an item in the array.
    3. Print out the list of all items.
    4. Sort the list.
    5. Exit.
  • Include a sub-menu for Sort option that allows the User to select which field they wish to sort by.
  • When your program is first executed, read data from an external file and place it in your array. Include a minimum of 5 sets of data in the file. Submit the external file with your program.
  • Save the data back to the external file when the Exit option is chosen from the menu in the Driver.

Sorting Algo.

Data:

outerLoop: Outer loop counter innerLoop: Inner loop counter location: Location of smallest value n = number of items in the array

Logic:

outerLoop runs from 0 to (number of items in array 1) initialize the location of the smallest value to the position indicated by the outerLoop value innerLoop runs from (outerLoop + 1) to the number of items in array IF the value in the array at position innerLoop is less than the smallest value at position location THEN replace the location of the smallest value into the location of the value in the array END IF end innerLoop swap the value of the new smallest with the value located at the position indicated by the outerLoop END outerLoop

Logic converted to pseudo-code:

FOR (outerLoop = 0 to (n 1) ) let location = outerLoop FOR (innerLoop = ((outerLoop + 1) to n) IF (value at array[innerLoop] is less than array[location]) THEN location = innerLoop END IF END FOR innerLoop swap array[outerLoop] with array[location] END FOR outerLoop

Download link to program: https://www.dropbox.com/s/eqp42kdh694m0fn/Dog.zip?dl=0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!