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
mixas84 [53]
2 years ago
10

[10] Create a program called SelectionSort.java that implements the Selection Sort algorithm (The Art of Computer Programming -

Donald Knuth). The algorithm is as follows: The program should be able to do the following: accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers in ascending order, and then prints out a sorted version of these integers, one per line. The implementation should follow the given the pseudo code/algorithm description.
Engineering
1 answer:
Alex787 [66]2 years ago
8 0

Answer:

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.Scanner;

public class SelectionSort {

  public static void main(String[] args) throws FileNotFoundException {

      //For array

      ArrayList<Integer>array=new ArrayList<Integer>();

      //If argument found

      if(args.length>=1) {

          //File path

          Scanner sc=new Scanner(new File(args[0]));

          //Loop until end

          while(sc.hasNextLine()) {

              //Read each line and add into array

              String[] temp=sc.nextLine().split(" ");

              for(int i=0;i<temp.length;i++) {

                  array.add(Integer.parseInt(temp[i]));

              }

          }

          //Display array

          System.out.println("Display array: ");

          printArray(array);

          System.out.println("\nDisplay array after sort: ");

          sortArray(array);

          printArray(array);

      }

      //If argument not found

      else {

          System.out.println("Argument not found!!!");

      }

  }

  //Method to print array

  public static void printArray(ArrayList<Integer>array) {

      for(int i=0;i<array.size();i++) {

          System.out.println(array.get(i));

      }

  }

  //Method to sort array using straight selection sort

  public static void sortArray(ArrayList<Integer>array) {

      //Step1

      for(int j=array.size()-1;j>=1;j--) {

          int max=array.get(j);

          int index=j;

          //Step2

          for(int k=j;k>=0;k--) {

              if(max<array.get(k)) {

                  max=array.get(k);

                  index=k;

              }

          }

          //Step3

          array.set(index,array.get(j));

          array.set(j,max);

      }

  }

}

Explanation:

You might be interested in
When would working with machinery be a common type of caught-in and caught-between<br> hazard?
tigry1 [53]

Answer:

A working with machinery be a common type of caught-in and caught-between  hazard is described below in complete detail.

Explanation:

“Caught in-between” accidents kill mechanics in a variety of techniques. These incorporate cave-ins and other hazards of tunneling activity; body parts extracted into unconscious machinery; reaching within the swing range of cranes and other installation material; caught between machine & fixed objects.

6 0
2 years ago
A dielectric material, such as Teflon®, is placed between the plates of a parallel-plate capacitor without altering the structur
Lina20 [59]

Answer: The electric field decreases because of the insertion of the Teflon.

Explanation:

If the charge on the capacitor is held fixed, the electric field as a consequence of this charge distribution (directed from the positive charged plate to the negative charged one remains unchanged.

However, as the Teflon is a dielectric material, even though doesn't allow the free movement of the electrons as an answer to an applied electric field, it allows that the electrons be displaced from the equilibrium position, leaving a local negative-charged zone close to the posiitive plate of the capacitor, and an equal but opposite charged layer close to the negative plate.

In this way, a internal electric field is created, that opposes to the external one due to the capacitor, which overall effect is diminishing the total electric field, reducing the voltage between the plates, and  increasing the capacitance proportionally to the dielectric constant of the Teflon.  

8 0
2 years ago
The link acts as part of the elevator control for a small airplane. If the attached aluminum tube has an inner diameter of 25 mm
aksik [14]

Answer:

Tmax=14.5MPa

Tmin=10.3MPa

Explanation:

T = 600 * 0.15 = 90N.m

T_max =\frac{T_c}{j}  = \frac{x}{y}  = \frac{90 \times 0.0175}{\frac{\pi}{2} \times (0.0175^4-0.0125^4)}

=14.5MPa

T_{min} =\frac{T_c}{j}  = \frac{x}{y}  = \frac{90 \times 0.0125}{\frac{\pi}{2} \times (0.0175^4-0.0125^4)}

=10.3MPa

7 0
2 years ago
provides steady-state operating data for a solar power plant that operates on a Rankine cycle with Refrigerant 134a as its worki
Vaselesa [24]

Answer:

hello some parts of your question is missing attached below is the missing part ( the required fig and table )

answer : The solar collector surface area = 7133 m^2

Explanation:

Given data :

Rate of energy input to the collectors from solar radiation = 0.3 kW/m^2

percentage of solar power absorbed by refrigerant = 60%

Determine the solar collector surface area

The solar collector surface area = 7133 m^2

attached below is a detailed solution of the problem

8 0
3 years ago
The theoretical maximum specific gravity of a mix at 5.0% binder content is 2.495. Using a binder specific gravity of 1.0, find
PSYCHO15rus [73]

Answer:

The theoretical maximum specific gravity at 6.5% binder content is 2.44.

Explanation:

Given the specific gravity at 5.0 %  binder content 2.495

Therefore

95 % mix + 5 % binder  gives S.G. = 2.495

Where the  binder is S.G. = 1, Therefore

Per 100 mass unit we have (Mx + 5)/(Vx + 5) = 2.495

(95 +5)/(Vx +5) = 2.495

2.495 × (Vx + 5) = 100

Vx =35.08 to 95

Or density of mix = Mx/Vx = 95/35.08 = 2.7081

Therefore when we have 6.5 % binder content, we get

Per 100 mass unit

93.5 Mass unit of Mx has a volume of

Mass/Density = 93.5/2.7081 = 34.526 volume units

Therefore we have

At 6.5 % binder content.

(100 mass unit)/(34.526 + 6.5) = 2.44

The theoretical maximum specific gravity at 6.5% binder content = 2.44.

3 0
2 years ago
Other questions:
  • A company specification calls for a steel component to have a minimum tensile strength of 1240 MPa. Tension tests are conducted
    7·1 answer
  • Liquid water enters an adiabatic piping system at 15°C at a rate of 8kg/s. If the water temperature rises by 0.2°C during flow d
    12·1 answer
  • 3–102 One of the common procedures in fitness programs is to determine the fat-to-muscle ratio of the body. This is based on the
    5·1 answer
  • What are the four basic parts of process plan
    11·1 answer
  • Estimate the uncertainty in a 22 m/sec air velocity measurement using a Pitot tube at 20C. Assume the atmospheric pressure is 1
    7·1 answer
  • Hiiiiiiiii<br> jhajwjne f f g. g g tnnjzjnsnsnend f najjwne d f nskiaksjsjsjksm
    5·1 answer
  • What is aviation? What is the difference between aviation and flight?
    9·1 answer
  • I need help due today please help
    5·1 answer
  • Explain what the engineering team should advise in the following scenario.
    7·1 answer
  • A solid steel shaft ABCDE turns freely in bearings at points A and E. The shaft is driven by the gear at C, which applies a torq
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!