Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class, UnsortedData, that has two public static methods: A method called countOutOfPosition that accepts as parameter an array of doubles, and returns a

Write a class, UnsortedData, that has two "public static" methods:

  • A method called countOutOfPosition that

    • accepts as parameter an array of doubles, and

    • returns a count of how far "out of position" all the items are. Do this by summing up (for each item "i" in the array) how many items after item "i" in the unsorted list are smaller than item "i".

  • A method called bubble that

    • takes as parameter and array of doubles, and

    • performs the following operation once on every item in the unsorted list: If an item is larger than the item after it, swap the items.

Write a UnsortedDataApp program, that

  • prompts the user for a name of an input file

  • reads 100 real numbers from that file. You can assume the file exists, and contains 100 valid real numbers.

  • Then:

    • call "countOutOfPosition method and display the result.

    • call "bubble" and your first function again and see if there items are not as far "out of position" as before.

Make sure you add try-catch sections that handle FileNotFoundException where appropriate.

Here is a sample run:

Sample run:

What is the name of the input file? dataRandom.txt

Total Out of Order BEFORE Bubble = 2604

Total Out of Order AFTER Bubble = 2508

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

Advances In Spatial Databases 2nd Symposium Ssd 91 Zurich Switzerland August 1991 Proceedings Lncs 525

Authors: Oliver Gunther ,Hans-Jorg Schek

1st Edition

3540544143, 978-3540544142

More Books

Students also viewed these Databases questions

Question

4. Label problematic uses of language and their remedies

Answered: 1 week ago