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
Python Codio Question:
tester [92]

Answer:

# -*- coding: utf-8 -*-

# Get N from the command line

import sys

N = int(sys.argv[1])

if N > 0: #N is positive  

   positve = list(range(N,0,-1))

   print(positve)

elif N < 0: #N is negative  

   negative = list(range(N,0,1))

   print(negative)

else:

   print("Invalid in input")

Explanation:

First, you need to identify if the number entered is positive, negative or none of them, for that we use one if, one elif and one else statement:

  • If the number entered (N) is greater than zero (is positive) we print a list in the range N to 0 in steps of minus one, the zero is not printed because the function range by default omits the last value
  • If the previous statement was False and the number entered is smaller than zero (is negative) we print a list in the range N to 0 in steps of one, the zero is not printed because the function range by default omits the last value
  • Finally, if the two previous events were false print invalid input

7 0
3 years ago
Assume we have already defined a variable of type String called password with the following line of code: password' can have any
omeli [17]

Answer:

The Java code is given below with appropriate comments for better understanding

Explanation:

import java.util.Scanner;

public class ValidatePassword {

  public static void main(String[] args) {

      Scanner input = new Scanner(System.in);

          System.out.print("Enter a password: ");

          String password = input.nextLine();

          int count = chkPswd(password);

          if (count >= 3)

              System.out.println("Secure");

          else

              System.out.println("Not Secure");

  }

  public static int chkPswd(String pwd) {

      int count = 0;

      if (checkForSpecial(pwd))

          count++;

      if (checkForUpperCasae(pwd))

          count++;

      if (checkForLowerCasae(pwd))

          count++;

      if (checkForDigit(pwd))

          count++;

      return count;

  }

  // checks if password has 8 characters

  public static boolean checkCharCount(String pwd) {

      return pwd.length() >= 7;

  }

  // checks if password has checkForUpperCasae

  public static boolean checkForUpperCasae(String pwd) {

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

          if (Character.isLetter(pwd.charAt(i)) && Character.isUpperCase(pwd.charAt(i)))

              return true;

      return false;

  }

  public static boolean checkForLowerCasae(String pwd) {

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

          if (Character.isLetter(pwd.charAt(i)) && Character.isLowerCase(pwd.charAt(i)))

              return true;

      return false;

  }

  // checks if password contains digit

  public static boolean checkForDigit(String pwd) {

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

          if (Character.isDigit(pwd.charAt(i)))

              return true;

      return false;

  }

  // checks if password has special char

  public static boolean checkForSpecial(String pwd) {

      String spl = "[email protected]#$%^&*(";

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

          if (spl.contains(pwd.charAt(i) + ""))

              return true;

      return false;

  }

}

5 0
3 years ago
What is integrated circuit package ​
enyata [817]

Answer:

Explanation:

, integrated circuit packaging is the final stage of semiconductor device fabrication, in which the block of semiconductor material is encapsulated in a supporting case that prevents physical damage and corrosion.

4 0
3 years ago
Read 2 more answers
If the reading of mercury manometer was 728 mmHg, what is the reading for another liquid such as water in mH20 units?​
vodka [1.7K]

Answer:

mH275 units

Explanation:

  • that was true
4 0
3 years ago
What is software certification? Discuss its importance in the changing scenario of software industry. ​
bekas [8.4K]

The software industry is evolving, and software certification is crucial. ​Software certification is a digitally signed certificate that verifies the identification of an individual or company. ​

<h3>What is software certification?</h3>

A certificate, sometimes known as a digital certificate, is a special document that has been digitally signed and authenticates the identity of a person or business.

Its validity may be checked using public-key cryptography to make sure that the program or website you are accessing is reliable.

Software developers must demonstrate that their program executes the XBRL conformance suites successfully in order to be certified.

They must also supply extra test cases so that XBRL employees can test the program further. The validity of certification is one year, renewable yearly.

Hence the software industry is evolving, and software certification is crucial. ​

To learn more about the software certification refer;

brainly.com/question/11299456

#SPJ1

6 0
2 years ago
Other questions:
  • You find a publication from a research laboratory that identifies a new catalyst for ammonia synthesis. The article contains the
    6·1 answer
  • Design a half-wave recti er which provides a peak voltage of 15 V, and anaverage voltage of 3.8 V when driven by a 120 V (rms) a
    10·1 answer
  • Choose the true statement from those shown below: A Merchant Account allows you to use SSL on your web site. Disadvantages of us
    14·1 answer
  • Describe how the Rotary Engine works.
    14·1 answer
  • Mahamad Siddiqui sent false emails and letters of recommendation on behalf of individuals without their permission to nominate h
    12·1 answer
  • A seamless pipe 800mm diameter contains a fluid under a pressure of 2N/mm2. If the permissible tensile stress is 100N/mm2, find
    11·1 answer
  • Three 12-V, 100-A-hr batteries are connected in series. What are the output voltage and A-hr capacity of this connection
    9·1 answer
  • 13. What two major safety problems does hydrogen present?
    8·2 answers
  • Which of the following justifies the need for an already-certified engineer to continue to take classes?
    15·1 answer
  • Suppose we are given three boxes, Box A contains 20 light bulbs, of which 10 are defective, Box B contains 15 light bulbs, of wh
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!