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]
3 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]3 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
thermodynamics A nuclear power plant based on the Rankine cycle operates with a boiling-water reactor to develop net cycle power
IrinaK [193]

Answer:

(a) the percent thermal efficiency is 27.94%

(b) the temperature of the cooling water exiting the condenser is 31.118°C

Explanation:

3 0
3 years ago
In a home, air infiltrates from the outside through cracks around doors and windows. Consider a residence where the total length
masya89 [10]

Answer:

Time period  = 41654.08 s

Explanation:

Given data:

Internal volume is 210 m^3

Rate of air infiltration  9.4 \times 10^{-5} kg/s

length of cracks 62 m

air density = 1.186 kg/m^3

Total rate of air infiltration = 9.4\times 10^{-5} \times 62 = 582.8\times 10{-5} kg/s

total volume of air  infiltration= \frac{582.8\times 10{-5}}{1.156} = 5.04\times 10^{-3} m^3/s

Time period = \frac{210}{5.04\times 10^{-3}} = 41654.08 s

3 0
3 years ago
An engineer designs a new bus that can drive 30 miles per gallon of fuel. Which of the following was likely one of the client’s
Marat540 [252]
What are the options?
7 0
4 years ago
Read 2 more answers
You are driving on a roadway with multiple lanes of travel in the same direction, and are approaching an emergency vehicle parke
solmaris [256]

Answer: a. Leave the lane closest to the emergency as soon as it is safe to do so, or slow down to a speed of 20 MPH below the posted speed limit.

Explanation:

Giving a way to the law enforcement vehicle and a medical emergency vehicle is necessary. If one approaches an emergency vehicle parked along the roadway one should change the lane as the vehicle may not move and the driver may also waste his or her time also one should also slow down his or her speed while approaching the vehicle as most of the emergency vehicle are in rush to reach the hospital so the driver should maintain some distance with the medical emergency vehicle.

7 0
3 years ago
Zachary finished an internship as a Software Quality Assurance Engineer. For which job is he best qualified?
astra-53 [7]

Answer:

B. A software development firm needs someone to find and fix bugs on multiple computer platforms.

Explanation:

A software quality assurance engineer is someone who monitors every phase of the software development process so as to ensure design quality, making sure that the software adheres to the standards set by the development company. Finding bugs would make this intern a amazing bug finder

6 0
3 years ago
Read 2 more answers
Other questions:
  • Name 3 ways in which robots have improved since the Ebola outbreak.
    11·1 answer
  • A motor vehicle has a mass of 1.8 tonnes and its wheelbase is 3 m. The centre of gravity of the vehicle is situated in the centr
    14·1 answer
  • 12. Dies are turned using a special tool called a/an
    10·1 answer
  • What is the modulus of resilience for a tensile test specimen with a nearly linear elastic region if the yield strength is 500MP
    6·2 answers
  • If you add 10 J of heat to a system so that the final temperature of the system is 200K, what is the change in entropy of the sy
    9·1 answer
  • Which of the following sentences uses the word malleable correctly?
    7·2 answers
  • soy nueva en esto me pudieran ayudar nadie me ayuda soy de peru y no endiendo nada de lo que me dicen alguie me puediera explica
    10·1 answer
  • An interrupted line of sight means changes in ......and .... are necessary for re-establishing a ......... to the driver’s path
    7·1 answer
  • REVVIVE ME MY MOM WALKED IN MY ROOM AND SCARED THE BAJESUS OUTTA ME
    5·2 answers
  • Nonconductive safety shoes can be safely worn in a potentially explosive environment.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!