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
For electronically deposited funds, such as an employee's direct deposit, when must banks make those funds available to the empl
Kazeer [188]
I'm in computers class and I would say
6 0
3 years ago
What is the impedance mismatch problem? Which of the three programming
kykrilka [37]

Answer:

The problem that created due to the difference in the model of programming language and the database model.

Explanation:

The practical relational model has three components which are as follows

1. Attributes

2. Datatypes

3. Tuples

To minimize this problem  

1. We switch low pass L-Network to high pass L-network

2. We switch high pass L-Network to low pass L-network

3. We use the impedence matching transformer

3 0
4 years ago
How are special characters added to a Word document? Check all that apply.
MrRissso [65]

It kinda depends on what you mean by special characters

7 0
3 years ago
Read 2 more answers
Select the correct answer. Which input device uses optical technology?
daser333 [38]

Answer:

barcode reader is the correct answer

8 0
3 years ago
You have just built a new system from scratch. you turn the computer on but the system boot fails and sounds a beep code. what m
IgorLugansk [536]
The issue would be that the memory was not installed or was not detected by the system. If this happens, the system boot will fail and a beep code is heard. The system would not show anything since all of the software are in the memory which was not installed or detected.
4 0
3 years ago
Other questions:
  • I need an answer fast !!! (APEX)
    13·1 answer
  • Name types of operating system with example
    5·1 answer
  • What computer is designed to meet the computing needs of several people simultaneously in a small to medium-size business enviro
    5·1 answer
  • What is sun and what does it do?
    12·2 answers
  • Define a class called Counter. An object of this class is used to count things so it records a count that is a non-negative whol
    12·1 answer
  • Describe five examples of civil engineering projects.
    6·1 answer
  • Login
    11·1 answer
  • Several disaster relief nonprofits want to create a centralized application and repository of information so that they can effic
    7·1 answer
  • Write a program code which asks for 80 numbers between 100 and 1000 to be entered.
    7·1 answer
  • outline 4 IDE features that makes software development much faster and more convenient than other alternatives.​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!