1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
n200080 [17]
3 years ago
14

1. Atestharnessprogramfortestingsortingmethodsisprovidedwiththeprogram iles.ItisintheileSorts.javainthech11.sortspackage.Theprog

ramincludes aswapmethodthatisusedbyallofthesortingmethodstoswaparrayelements. a. Describeanapproachtomodifyingtheprogramsothataftercallingasorting methodtheprogramprintsoutthenumberofswapsneededbythesorting method. b. Implementyourapproach. c. TestyournewprogrambyrunningtheselectionSortmethod.Yourprogram shouldreport49swaps.
Computers and Technology
1 answer:
tiny-mole [99]3 years ago
3 0

Answer:

Following are the code to this question:

//import package

import java.util.*;

import java.text.*;

public class Main//defining a class

{

static final int t = 50;//defining an integer constant variable

static int[] ele = new int[t];//defining an array

static int tS = 0;//defining integer variable

static void initelements()//defining a static method

{

Random r= new Random();//creating Random class Object

for (int i = 0; i < t; i++)//use loop to add value in array

ele[i] = Math.abs(r.nextInt()) % 100;//add value in array

}

static public boolean isSorted()//defining a method isSorted

{

boolean x = true;//defining boolean variable

for (int i = 0; i < (t - 1); i++)//use for loop to count array values

if (ele[i] > ele[i + 1])//use if to compare array values

x = false;//use boolean variable to hold false value

return x;//return boolean value

}

static public void swap(int x1, int x2)//defining swap method

{

tS++;//increment variable value by 1

//performing swapping

int te = ele[x1];//defining te variable that holds array values

ele[x1] = ele[x2];//exchanging array values

ele[x2] = te;//holding te values

}

static public void disp()//defining a method disp

{

int v1;

DecimalFormat f = new DecimalFormat("00");//creating DecimalFormat class Object

System.out.println("The elements array is:");//print message

for (int i = 0; i <t; i++)//defining for loop  

{

v1 = ele[i];//holding array value in v1 variable

if (((i + 1) % 10) == 0)//use if to check i value

System.out.println(f.format(v1));//print value

else//else block

System.out.print(f.format(v1) + " ");//print value

}

System.out.println();//print space

}

static int getMinimum(int st, int en)//defining a method getMinimum

{

int iMi = st;//defining variable that holds parameter value

for (int i = st + 1; i <= en; i++)//use for loop compare array value

if (ele[i] < ele[iMi])//compare array value

iMi = i;//use iMi to hold loop value

return iMi;//return iMi value

}

static void selectionSort()//defining a selectionSort method

{

int e = t - 1;//defining e variable that holds total array count value

for (int i = 0; i < e; i++)//use for loop to call swap method  

swap(i, getMinimum(i, e));//calling the swap method

}

public static void main(String[] args)//defining main method  

{

initelements();//calling initelements method

disp();//calling disp method

System.out.println("elements is sorted: " + isSorted());//calling is isSorted method with the message

System.out.println();//for space

selectionSort();//calling selectionSort method

System.out.println("No of swaps :" + tS);//print totalswap value with the message

disp();//calling disp method

System.out.println("elements is sorted: " + isSorted());//calling is isSorted method with the message

System.out.println();//for space

}

}

Output:

Please find the attached file.

Explanation:

In this code inside the Main class, 5 static methods "initelements, isSorted, swap, disp, getMinimum and selectionSort" is declared, in which the first method holds random values in arrays, in second array it sorts its values, in the third method it swap the array, in the disp method it shows array values.

In the "getMinimum and selectionSort"  it sorts array values and inside the main method, it calls all methods and prints their values.

You might be interested in
Several programmers write individual code modules that are used for different processes in a vehicle. Individual tests have alre
Arte-miy333 [17]

Answer:

Integration.

Explanation:

Integration testing can be defined as a phase in software applications testing, which typically involves the process of testing the interface between two software module combined as a group.

The main purpose of an integration testing is to determine the correctness of this interface and expose any fault existing between integrated modules.

In this scenario, several programmers wrote individual code modules that are used for different processes in a vehicle and individual tests have already been done. Now it is the time to put all of the modules together and test the system as a whole. Therefore, this type of testing is known as integration testing.

5 0
3 years ago
Which can be inserted using the insert panel in dreamweaver cc?
timofeeve [1]

Answer: Learn how to use the Insert panel in Dreamweaver to create and insert objects, such as tables, images, OAM files, and Bootstrap components. The Insert panel contains buttons for creating and inserting objects such as tables and images. The buttons are organized into categories.

3 0
4 years ago
Hey!! Can u help me please!!​
igor_vitrenko [27]

1. deletes file named school.txt

2 copy Aic.txt to windows

3. display the volume label and serial number if logical drive

4. remove directory named ASIAN

5.lists all files and sub directories of OS

6. displays current date and time

3 0
3 years ago
Read 2 more answers
What do you call the processing of converting an image to binary?
frutty [35]

Question

What do you call the processing of converting an image to binary?

Answer:

Thresholding Is the Answer!

Explanation:

In thresholding, we convert an image from color or grayscale into a binary image, i.e., one that is simply black and white.

Hope this helps!

6 0
3 years ago
Read 2 more answers
The vertical and horizontal scroll bars can be used to aid in navigation throughout the document. true or false
Triss [41]

Answer: True

Hope this helps :)

7 0
3 years ago
Read 2 more answers
Other questions:
  • How are the stop lamp bulbs connected in relation to each other? a. In parallel. b. In series. c. In series/parallel. d. None of
    13·1 answer
  • Technologies that allow for instant worldwide communication include satellite and computer systems. mobile phones and internet a
    8·2 answers
  • Encapsulation is the process of “packaging” information prior to transmitting it from one location to another. true or false
    14·1 answer
  • Can Anybody Answer This
    8·1 answer
  • Which term describes the second core IPSec security protocol; it can perform authentication to provide integrity protection, alt
    13·1 answer
  • Successful implementation of an effective MRP system depends upon (1) the recognition of the difference between independent and
    13·1 answer
  • What is the useful chart used for comparing values over categories?​
    8·1 answer
  • My brainly has broke- XD
    11·1 answer
  • An algorithm is Group of answer choices The part of the computer that does the processing A complete computer program The inputs
    6·1 answer
  • Find the name of the professor with the maximum percentage of students that failed his course.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!