Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Problem

Sorting is a frequent array operation.  An array can be sorted if there is an ordering relation between the elements in array.  For illustration, if the array comprises a set of integer elements, we can order the elements according to integer number line.  A common technique whereby the elements in an array might be sorted is called the bubble sort.  Supposing an array of positive integers which we wish to sort according to the sequence represented by integer number line, the bubble sort operates as follows:

1.  Find out the two adjacent elements, X and Y, in the array such that X > Y and swap X and Y, then sort the resulting array.

2.  If there is no adjacent pair of the elements, X and Y, in the array such that X > Y, the list is sorted.

Note that the reason of swapping two elements X and Y that occur out of order is so that after the swap, the new list is closer to a sorted list.  After a sufficient amount of swapping, we must end up with all the elements in order.  For illustration given the array:

{1 2 5 4 7 3 6 8 10 9}

We would commence by the finding elements 5 and 4 and swap them to get:

{1 2 4 5 7 3 6 8 10 9}

We would then continue as follows:

{1 2 4 5 7 3 6 8 10 9}
{1 2 4 5 3 7 6 8 10 9}
{1 2 4 3 5 7 6 8 10 9}
{1 2 3 4 5 7 6 8 10 9}
{1 2 3 4 5 6 7 8 10 9}
{1 2 3 4 5 6 7 8 9 10}

The procedure is known as a bubble sort since elements slowly bubble up to their correct location.

Implement and Design a Java program which sorts a 10 element integer array using bubble sort procedure.  The elements of the array to be sorted must be supplied by the user (assume the user will not input duplicates).

Make a GUI front end for your bubble sort program.  The result must look something like that presented in Figure.  You might use any graphic element to make your display - JOptionPanesare the easiest and most basic tools accessible to you, but you might also experiment with additional GUI controls such as JFrames, JPanels, etc.  I would advise you to use objects from the Swing library (those objects begin with 'J') as opposed to objects from AWT library - Swing objects are a little easier to use and are ultimately more flexible and robust than AWT objects.

In the illustration below, there are 10 text fields on a JFrame background to allow input of array elements (remember that for each text field you should press the carriage return key to invoke the listener).  When the array has been populated, we press the start button, at which point the given array is output as a label.  We then sort the output and result the sorted array.

Hint: Don’t attempt to make the GUI too sophisticated.  Just concentrate on producing a working result (although sound programming techniques should still be applied).

1061_buble sort_1.jpg

Figure: Bubble sort GUI (partial ex)

Remember to prepare the source code for each class in a separate file which should have the same name as the class name together with extension .java.  Remember also that by convention, class names commence with a capital letter.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91529

Have any Question?


Related Questions in Programming Language

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Question 1 what is hadoop explaining hadoop 2 what is

Question: 1. What is Hadoop (Explaining Hadoop) ? 2. What is HDFS? 3. What is YARN (Yet Another Resource Negotiator)? The response must be typed, single spaced, must be in times new roman font (size 12) and must follow t ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Extend the adworks applicationi add dialogs to allow the

Extend the AdWorks application I. Add Dialogs to allow the user to Add, Edit, Read and Delete a Customer and refresh the view accordingly. 1. The user should be able to select a specific customer from the DataGrid and cl ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As