Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my UnsortedData class: class UnsortedData{ public static int countOutOfPosition(double arr[]){ int count = 0; for(int i=0; i <100; i++){ for(int j=i+1; j <100;

This is my UnsortedData class:

class UnsortedData{ public static int countOutOfPosition(double arr[]){ int count = 0; for(int i=0; i<100; i++){ for(int j=i+1; j<100; j++){ if(arr[i] > arr[j]){ count ++; } } } return count; } public static double [] Bubble(double arr[]){ double t; for(int i=0; i<99; i++){ if(arr[i] > arr[i+1]){ t = arr[i]; arr[i] = arr[i+1]; arr[i+1] = t; } } return arr; } }

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

Database Theory And Application Bio Science And Bio Technology International Conferences DTA And BSBT 2011 Held As Part Of The Future Generation In Computer And Information Science 258

Authors: Tai-hoon Kim ,Hojjat Adeli ,Alfredo Cuzzocrea ,Tughrul Arslan ,Yanchun Zhang ,Jianhua Ma ,Kyo-il Chung ,Siti Mariyam ,Xiaofeng Song

2011th Edition

3642271561, 978-3642271564

Students also viewed these Databases questions

Question

6. Why does what I can say matter more than how I say it?

Answered: 1 week ago

Question

1. Why do people tell lies on their CVs?

Answered: 1 week ago

Question

2. What is the difference between an embellishment and a lie?

Answered: 1 week ago