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
What are the reasons why is it necessary to evaluate online sources and content?
marissa [1.9K]
1) You don't know if the source is reliable. 
2) It is better to cite reliable sources so.
7 0
3 years ago
If ADD = 81, BAD = 49, and CAD = 64, then what is the value of ACA?
Digiron [165]

Answer:

its 72

Explanation:

i know it because i did it and thats how i know it

6 0
3 years ago
Which of the following would not be considered a PC?
Rudik [331]
I'm not sure...but it might be a tablet
5 0
3 years ago
Read 2 more answers
What is e banking effects
Dmitriy789 [7]

Answer:

Mainly things:

  1. You don't have to drive to the bank.
  2. You don't have to wait for a teller and spend time at the bank.
  3. You can transfer money to other accounts faster and more securely.
  4. You can easily view your statements on your phone or computer.  
  5. Have easier access to your accounts and information.
  6. More

4 0
2 years ago
1. We want to add a button to the tally counter in Section 9.2 that allows an operator to undo an accidental button click. Provi
serious [3.7K]

Answer:

See explaination

Explanation:

class Counter:

def getValue(self):

return self._value

def undo(self):

if self._value > 0:

self._value = self._value - 1;

def click(self):

self._value= self._value + 1

def reset(self):

self._value= 0

tally= Counter()

tally.reset()

tally.click()

tally.click()

result = tally.getValue()

print("Value:", result)

tally.click()

result = tally.getValue()

print("Value:", result)

tally.undo()

tally.undo()

result = tally.getValue()

print("Value:", result)

tally.undo()

tally.undo()

result = tally.getValue()

print("Value:", result)

5 0
3 years ago
Other questions:
  • Can your computer become infected with a virus via email
    6·1 answer
  • Input numbers and segregate them by placing their values into even or odd vectors based upon their value being even or odd. Then
    12·1 answer
  • How does a main program recieve info from a function in c++?
    6·1 answer
  • HELP ME WITH JAVA: This is my assignment. I need to write a program with a main method and methods. Use a scanner to get the Str
    5·1 answer
  • People who score high on the Big Five trait dimension of ________ tend to use more adjectives in their e-mail communications. Gr
    15·1 answer
  • The ____________ deals with the well-being of the EMT, career progression, and EMT compensation. Select one: A. EMS administrato
    9·1 answer
  • The File method lastModified() returns
    10·1 answer
  • The following procedure is intended to return the number of times the value val appears in the list nylist. The procedure does n
    15·2 answers
  • Un polímero sintético es renovable o no renovable
    11·1 answer
  • What would be the printed output of the Python code to the right?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!