Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My program is giving a wierd output and I don\'t know why and the bug. Can someo

ID: 3723828 • Letter: M

Question

My program is giving a wierd output and I don't know why and the bug. Can someone try to find the bug and fix it then give a lil'll bit of explanation what was the bug.

import java.util.*;

import java.io.*;

public class P5Sort{

      private ArrayList<Integer> listInt; // List of integer numbers

   private ArrayList<String> stringList; //List of String words

   private String fileName; // File name for the Output file

   private String outputString; // Output String

   private String outputFile; // File name for the Output file

   private final String LS = System.lineSeparator();

   private Scanner scan;

   private long startSystemTime; // CPU clock startindg time for int

   private long endSystemTime; // CPU clock starting time for float

   private long startTime; // Wall clock starting time for int

   private long endTime;

   private double cpuTimeSelectionSort;

   private double cpuTimeBubbleSort;

   private double cpuTimeCollection;

   private double cpuTimeSelectionSortInt;

   private double cpuTimeBubbleSortInt;

   private double cpuTimeCollectionInt;

   private double wallClockSelectionSort;

   private double wallClockBubbleSort;

   private double wallClockCollectionSort;

   private double wallClockSelectionSortInt;

   private double wallClockBubbleSortInt;

   private double wallClockCollectionSortInt;

   public P5Sort() {

       listInt = new ArrayList<Integer>();

      stringList = new ArrayList<String>();

      fileName = null;

      outputFile = "P5Output.txt";

   scan = new Scanner(System.in);

   }

   public static void main(String[] args) {

       P5Sort sort = new P5Sort();

      sort.timingSots();

   }

  

   public void timingSots(){

  

      System.out.println("Please enter a valid Input file name that have Words and also with .txt ... ");

     

      fileName = scan.nextLine();

     

      readTheFilesForString();

  

      System.out.println("Please enter a valid Input file name that have Numbers and also with .txt ... ");

         

      fileName = scan.nextLine();

  

      readTheFilesForInt();

  

      // Timing selction sort for an Arralist of String

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   selectionSort();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockSelectionSort = (double)(endTime - startTime) / 1000.0;

   cpuTimeSelectionSort = (double)(endSystemTime - startSystemTime) / 100000000.0;

  

      // Timing bubble sort for an Arralist of Strings

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   bubbleSort();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockBubbleSort = (double) (endTime - startTime) / 1000.0;

   cpuTimeBubbleSort = (double) (endSystemTime - startSystemTime) / 1000000000.0;

  

      // Timing collection sort in an Arraylist of Strings

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   collectionSortString();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockCollectionSort = (double) (endTime - startTime) / 1000.0;

   cpuTimeCollection = (double) (endSystemTime - startSystemTime) / 1000000000.0;

     

      // Timing selction sort for an Arraylist of Integers

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   selectionSortInt();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockSelectionSortInt = (double) (endTime - startTime) / 1000.0;

   cpuTimeSelectionSortInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

      // Timing bubble sort for an Arraylist of Integers

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   bubbleSortInt();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockBubbleSortInt = (double) (endTime - startTime) / 1000.0;

   cpuTimeBubbleSortInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

  

      // Timing selection sort for an Arraylist of Integers

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   selectionSortInt();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockSelectionSortInt = (double) (endTime - startTime) / 1000.0;

   cpuTimeSelectionSortInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

  

      // Timing collection sort for an Arraylist of Integers

   startTime = System.currentTimeMillis();

   startSystemTime = System.nanoTime();

  

   collectionSort();

  

   endTime = System.currentTimeMillis();

   endSystemTime = System.nanoTime();

  

   wallClockCollectionSortInt = (double) (endTime - startTime) / 1000.0;

   cpuTimeCollectionInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

  

      outputToFile();

   }// end of mainMenu

   public void selectionSort(){

     

      int minValue = 0;

     

      int startScan;

     

      int index;

     

      String temp;

     

      for( startScan = 0; startScan < stringList.size(); startScan++){

   stringList.set( minValue, stringList.get(startScan));

   for( index = startScan + 1; index < stringList.size(); index++){

      if((stringList.get(index)).compareToIgnoreCase(stringList.get(startScan))<0){

  

   temp = stringList.get(startScan);

   stringList.set( startScan, stringList.get(index));

   stringList.set(index , temp);

      }

   }

   System.out.println(stringList.get(startScan));

      }     

   }// end of selection sort

  

   public void selectionSortInt(){

     

      int minValue = 0;

     

      int startScan;

     

      int index;

     

      int temp;

     

      for( startScan = 0; startScan < listInt.size(); startScan++){

   listInt.set( minValue, listInt.get(startScan));

   for( index = startScan + 1; index < listInt.size(); index++){

      if((listInt.get(index)) < (listInt.get(startScan))){

  

   temp = listInt.get(startScan);

   listInt.set( startScan, listInt.get(index));

   listInt.set(index , temp);

      }

   }

   System.out.println(stringList.get(startScan));

      }

   }// end of selectionSortInt

  

   public void bubbleSort(){

     

      int startScan;

     

      int index;

     

      String temp;

     

      for( startScan = 0;startScan < stringList.size();startScan++){

  

   for( index = startScan + 1;index < stringList.size();index++){

      if((stringList.get(index)).compareToIgnoreCase(stringList.get(startScan))<0){

  

   temp = stringList.get(startScan);

   stringList.set( startScan, stringList.get(index));

   stringList.set(index , temp);

      }

   }

   System.out.println(stringList.get(startScan));

      }

   }// end of bubbleSort

  

   public void bubbleSortInt(){

      int startScan;

     

      int index;

     

      int temp;

     

      for( startScan = 0;startScan < listInt.size();startScan++){

  

   for(index = startScan + 1;index <listInt.size();index++){

      if((listInt.get(index)) < (listInt.get(startScan))){

  

   temp = listInt.get(startScan);

   listInt.set( startScan, listInt.get(index));

   listInt.set(index , temp);

      }

   }

   System.out.println(stringList.get(startScan));

      }

   }// end of bubbleSortInt

  

   public void collectionSort(){

     

      Collections.sort(listInt);

     

   }

  

   public void collectionSortString(){

      Collections.sort(stringList);

     

   }

   public void readTheFilesForString(){

     

      String content = new String();

      File file = new File(fileName);

      try {

   Scanner sc = new Scanner(new FileInputStream(file));

   while (sc.hasNextLine()){

      content = sc.nextLine();

      stringList.add(content);

   }

   sc.close();

      }catch(FileNotFoundException fnf){

   System.out.println("File not found.");

   System.exit(0);

      }

      catch (Exception e) {

   System.out.println(" Program terminated Safely...");

      }

     

      }// end of readTheFilesForString

   public void readTheFilesForInt(){

     

      int integerContent = 0;

      File file = new File(fileName);

      try {

   Scanner sc = new Scanner(new FileInputStream(file));

   while (sc.hasNextLine()){

      integerContent = sc.nextInt();

      listInt.add(integerContent);

   }

   sc.close();

      }catch(FileNotFoundException fnf){

   System.out.println("File not found.");

   System.exit(0);

      }

      catch (Exception e) {

   System.out.println(" Program terminated Safely...");

      }

      }// end of readTheFilesForInt

   /**

   * Prints the report with the data from the trial

   */

   public void outputToFile(){

     

      outputString = "There are " + stringList.size() + " words in the list" +

   LS + "There are " + listInt.size() + " numbers in the list " +

   LS + "Selection sort for Strings " + "- " + cpuTimeSelectionSort + " seconds CPU time. " +

   LS + "Selection sort for Integers " + "- " + cpuTimeSelectionSortInt + " seconds CPU time. " +

   LS + "Bubble sort for String " + "- " + cpuTimeBubbleSort + " seconds CPU time. " +

   LS + "Bubble sort for Integers " + "- " + cpuTimeBubbleSortInt + " seconds CPU time. " +

   LS + "Collection sort for Strings " + "- " + cpuTimeCollection + " seconds CPU time. " +

   LS + "Collection sort Integers " + "- " + cpuTimeCollectionInt + " seconds CPU time. " +

   LS + "Selection sort for Strings " + "- " + wallClockSelectionSort + " seconds wall clock " +

   LS + "Selection sort for Integers " + "- " + wallClockSelectionSortInt + " seconds wall clock " +

   LS + "Bubble sort for String " + "- " + wallClockBubbleSort + " seconds wall clock " +

   LS + "Bubble sort for Integers " + "- " + wallClockBubbleSortInt + " seconds wall clock " +

   LS + "Collection sort for Strings " + "- " + wallClockCollectionSort + " seconds wall clock " +

   LS + "Collection sort Integers " + "- " + wallClockCollectionSortInt +" seconds wall clock " + LS + LS;

     

      System.out.println(outputString);

      writeReport(outputString);

   }// end of outputToFile

  

   /**

   * Writes the report with the data from the trial

   */

   private void writeReport(String reportString){

      try{

   BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outputFile), true));

   writer.write(reportString);

   writer.close();

      }catch(Exception ex){

   System.out.println("try a different file name");

      }

   }

}

This is the output

Please enter a valid Input file name that have Words and also with .txt ...

test.txt

Please enter a valid Input file name that have Numbers and also with .txt ...

testnumber.txt

Program terminated Safely...

  

- 0 seconds wall clock

- 0 seconds wall clock

- 0 seconds wall clock

- 22 seconds wall clock

- 22 seconds wall clock

- 53 seconds wall clock

A

B

Bubble sort for Integers - 0 seconds CPU time 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0.0 seconds CPU time. - 0.0 seconds wall clock

Bubble sort for Integers -0 seconds CPU time 0 seconds wall clock

Bubble sort for String - 10229700 seconds CPU time. - 10 seconds wall clock

Bubble sort for String - 107475629 seconds CPU time.

Bubble sort for String - 108 seconds wall clock

Bubble sort for String - 116 seconds wall clock

Bubble sort for String - 116162447 seconds CPU time.

Bubble sort for String - 117931877 seconds CPU time.

Bubble sort for String - 118 seconds wall clock

Bubble sort for String - 126 seconds wall clock

Bubble sort for String - 126092774 seconds CPU time.

Bubble sort for String - 137931632 seconds CPU time.

Bubble sort for String - 138 seconds wall clock

Bubble sort for String - 20730416 seconds CPU time. - 21 seconds wall clock

Bubble sort for String - 22282692 seconds CPU time.

Bubble sort for String - 29390052 seconds CPU time. - 30 seconds wall clock

Bubble sort for String - 31110141 seconds CPU time. - 31 seconds wall clock

Bubble sort for String - 4.5984905E7 seconds CPU time. - 46.0 seconds wall clock

Bubble sort for String - 43 seconds wall clock

Bubble sort for String - 43075995 seconds CPU time.

Bubble sort for String - 4407858 seconds CPU time 4 seconds wall clock

Bubble sort for String - 54 seconds wall clock

Bubble sort for String - 54089090 seconds CPU time.

Bubble sort for String - 65 seconds wall clock

Bubble sort for String - 65373263 seconds CPU time.

Bubble sort for String - 72624898 seconds CPU time.

Bubble sort for String - 73 seconds wall clock

Bubble sort for String - 75465591 seconds CPU time.

Bubble sort for String - 76 seconds wall clock

Bubble sort for String - 86 seconds wall clock

Bubble sort for String - 86329580 seconds CPU time.

Bubble sort for String - 95883524 seconds CPU time.

Bubble sort for String - 96 seconds wall clock

Bubble sort for String -2886403 seconds CPU time 3 seconds wall clock

C

Collection sort for Strings - 105 seconds wall clock

Collection sort for Strings - 105133252 seconds CPU time.

Collection sort for Strings - 127 seconds wall clock

Collection sort for Strings - 127034147 seconds CPU time.

Collection sort for Strings - 127769189 seconds CPU time.

Collection sort for Strings - 128 seconds wall clock

Collection sort for Strings - 128 seconds wall clock

Collection sort for Strings - 128344638 seconds CPU time.

Collection sort for Strings - 14218728 seconds CPU time. - 14 seconds wall clock

Collection sort for Strings - 22337229 seconds CPU time.

Collection sort for Strings - 31023327 seconds CPU time. - 31 seconds wall clock

Collection sort for Strings - 33358082 seconds CPU time. - 33 seconds wall clock

Collection sort for Strings - 4.1737164E7 seconds CPU time. - 42.0 seconds wall clock

Collection sort for Strings - 54 seconds wall clock

Collection sort for Strings - 54570081 seconds CPU time.

Collection sort for Strings - 55 seconds wall clock

Collection sort for Strings - 55358822 seconds CPU time.

Collection sort for Strings - 62 seconds wall clock

Collection sort for Strings - 62582047 seconds CPU time.

Collection sort for Strings - 6508161 seconds CPU time 6 seconds wall clock

Collection sort for Strings - 74 seconds wall clock

Collection sort for Strings - 74825975 seconds CPU time.

Collection sort for Strings - 85777514 seconds CPU time.

Collection sort for Strings - 86 seconds wall clock

Collection sort for Strings - 86551900 seconds CPU time.

Collection sort for Strings - 87 seconds wall clock

Collection sort for Strings - 96 seconds wall clock

Collection sort for Strings - 96412330 seconds CPU time.

Collection sort for Strings - 96478866 seconds CPU time.

Collection sort for Strings - 97 seconds wall clock

Collection sort for Strings - 9890110 seconds CPU time. - 10 seconds wall clock

Collection sort for Strings -2353380 seconds CPU time 3 seconds wall clock

Collection sort Integers - 0 seconds CPU time 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0.0 seconds CPU time. - 0.0 seconds wall clock

Collection sort Integers -0 seconds CPU time 0 seconds wall clock

D

E

F

G

H

I

J

L

LutherThis is the output file for the results

M

N

O

P

Q

R

S

Selection sort for Integers - 0 seconds CPU time 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0.0 seconds CPU time. - 0.0 seconds wall clock

Selection sort for Integers -0 seconds CPU time 0 seconds wall clock

Selection sort for Strings - 117457937 seconds CPU time.

Selection sort for Strings - 118 seconds wall clock

Selection sort for Strings - 121 seconds wall clock

Selection sort for Strings - 121198737 seconds CPU time.

Selection sort for Strings - 127908323 seconds CPU time.

Selection sort for Strings - 128 seconds wall clock

Selection sort for Strings - 132922501 seconds CPU time.

Selection sort for Strings - 133 seconds wall clock

Selection sort for Strings - 147680789 seconds CPU time.

Selection sort for Strings - 148 seconds wall clock

Selection sort for Strings - 162 seconds wall clock

Selection sort for Strings - 162531782 seconds CPU time.

Selection sort for Strings - 166666278 seconds CPU time.

Selection sort for Strings - 167 seconds wall clock

Selection sort for Strings - 175821698 seconds CPU time.

Selection sort for Strings - 176 seconds wall clock

Selection sort for Strings - 178 seconds wall clock

Selection sort for Strings - 178526945 seconds CPU time.

Selection sort for Strings - 36437601 seconds CPU time 36 seconds wall clock

Selection sort for Strings - 44352520 seconds CPU time. - 44 seconds wall clock

Selection sort for Strings - 47421951 seconds CPU time. - 47 seconds wall clock

Selection sort for Strings - 52596503 seconds CPU time.

Selection sort for Strings - 57022440 seconds CPU time. - 57 seconds wall clock

Selection sort for Strings - 64739546 seconds CPU time. - 65 seconds wall clock

Selection sort for Strings - 8.4247695E7 seconds CPU time. - 84.0 seconds wall clock

Selection sort for Strings - 85486091 seconds CPU time.

Selection sort for Strings - 86 seconds wall clock

Selection sort for Strings - 89961227 seconds CPU time.

Selection sort for Strings - 90 seconds wall clock

Selection sort for Strings - 93555451 seconds CPU time.

Selection sort for Strings - 94 seconds wall clock

Selection sort for Strings -33841883 seconds CPU time 33 seconds wall clock

T

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

U

V

W

X

Y

Y

Z

  

- 0 seconds wall clock

- 0 seconds wall clock

- 0 seconds wall clock

- 22 seconds wall clock

- 22 seconds wall clock

- 53 seconds wall clock

A

B

Bubble sort for Integers - 0 seconds CPU time 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time.

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0 seconds wall clock

Bubble sort for Integers - 0.0 seconds CPU time. - 0.0 seconds wall clock

Bubble sort for Integers -0 seconds CPU time 0 seconds wall clock

Bubble sort for String - 10229700 seconds CPU time. - 10 seconds wall clock

Bubble sort for String - 107475629 seconds CPU time.

Bubble sort for String - 108 seconds wall clock

Bubble sort for String - 116 seconds wall clock

Bubble sort for String - 116162447 seconds CPU time.

Bubble sort for String - 117931877 seconds CPU time.

Bubble sort for String - 118 seconds wall clock

Bubble sort for String - 126 seconds wall clock

Bubble sort for String - 126092774 seconds CPU time.

Bubble sort for String - 137931632 seconds CPU time.

Bubble sort for String - 138 seconds wall clock

Bubble sort for String - 20730416 seconds CPU time. - 21 seconds wall clock

Bubble sort for String - 22282692 seconds CPU time.

Bubble sort for String - 29390052 seconds CPU time. - 30 seconds wall clock

Bubble sort for String - 31110141 seconds CPU time. - 31 seconds wall clock

Bubble sort for String - 4.5984905E7 seconds CPU time. - 46.0 seconds wall clock

Bubble sort for String - 43 seconds wall clock

Bubble sort for String - 43075995 seconds CPU time.

Bubble sort for String - 4407858 seconds CPU time 4 seconds wall clock

Bubble sort for String - 54 seconds wall clock

Bubble sort for String - 54089090 seconds CPU time.

Bubble sort for String - 65 seconds wall clock

Bubble sort for String - 65373263 seconds CPU time.

Bubble sort for String - 72624898 seconds CPU time.

Bubble sort for String - 73 seconds wall clock

Bubble sort for String - 75465591 seconds CPU time.

Bubble sort for String - 76 seconds wall clock

Bubble sort for String - 86 seconds wall clock

Bubble sort for String - 86329580 seconds CPU time.

Bubble sort for String - 95883524 seconds CPU time.

Bubble sort for String - 96 seconds wall clock

Bubble sort for String -2886403 seconds CPU time 3 seconds wall clock

C

Collection sort for Strings - 105 seconds wall clock

Collection sort for Strings - 105133252 seconds CPU time.

Collection sort for Strings - 127 seconds wall clock

Collection sort for Strings - 127034147 seconds CPU time.

Collection sort for Strings - 127769189 seconds CPU time.

Collection sort for Strings - 128 seconds wall clock

Collection sort for Strings - 128 seconds wall clock

Collection sort for Strings - 128344638 seconds CPU time.

Collection sort for Strings - 14218728 seconds CPU time. - 14 seconds wall clock

Collection sort for Strings - 22337229 seconds CPU time.

Collection sort for Strings - 31023327 seconds CPU time. - 31 seconds wall clock

Collection sort for Strings - 33358082 seconds CPU time. - 33 seconds wall clock

Collection sort for Strings - 4.1737164E7 seconds CPU time. - 42.0 seconds wall clock

Collection sort for Strings - 54 seconds wall clock

Collection sort for Strings - 54570081 seconds CPU time.

Collection sort for Strings - 55 seconds wall clock

Collection sort for Strings - 55358822 seconds CPU time.

Collection sort for Strings - 62 seconds wall clock

Collection sort for Strings - 62582047 seconds CPU time.

Collection sort for Strings - 6508161 seconds CPU time 6 seconds wall clock

Collection sort for Strings - 74 seconds wall clock

Collection sort for Strings - 74825975 seconds CPU time.

Collection sort for Strings - 85777514 seconds CPU time.

Collection sort for Strings - 86 seconds wall clock

Collection sort for Strings - 86551900 seconds CPU time.

Collection sort for Strings - 87 seconds wall clock

Collection sort for Strings - 96 seconds wall clock

Collection sort for Strings - 96412330 seconds CPU time.

Collection sort for Strings - 96478866 seconds CPU time.

Collection sort for Strings - 97 seconds wall clock

Collection sort for Strings - 9890110 seconds CPU time. - 10 seconds wall clock

Collection sort for Strings -2353380 seconds CPU time 3 seconds wall clock

Collection sort Integers - 0 seconds CPU time 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time.

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds CPU time. - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0 seconds wall clock

Collection sort Integers - 0.0 seconds CPU time. - 0.0 seconds wall clock

Collection sort Integers -0 seconds CPU time 0 seconds wall clock

D

E

F

G

H

I

J

L

LutherThis is the output file for the results

M

N

O

P

Q

R

S

Selection sort for Integers - 0 seconds CPU time 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time.

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds CPU time. - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0 seconds wall clock

Selection sort for Integers - 0.0 seconds CPU time. - 0.0 seconds wall clock

Selection sort for Integers -0 seconds CPU time 0 seconds wall clock

Selection sort for Strings - 117457937 seconds CPU time.

Selection sort for Strings - 118 seconds wall clock

Selection sort for Strings - 121 seconds wall clock

Selection sort for Strings - 121198737 seconds CPU time.

Selection sort for Strings - 127908323 seconds CPU time.

Selection sort for Strings - 128 seconds wall clock

Selection sort for Strings - 132922501 seconds CPU time.

Selection sort for Strings - 133 seconds wall clock

Selection sort for Strings - 147680789 seconds CPU time.

Selection sort for Strings - 148 seconds wall clock

Selection sort for Strings - 162 seconds wall clock

Selection sort for Strings - 162531782 seconds CPU time.

Selection sort for Strings - 166666278 seconds CPU time.

Selection sort for Strings - 167 seconds wall clock

Selection sort for Strings - 175821698 seconds CPU time.

Selection sort for Strings - 176 seconds wall clock

Selection sort for Strings - 178 seconds wall clock

Selection sort for Strings - 178526945 seconds CPU time.

Selection sort for Strings - 36437601 seconds CPU time 36 seconds wall clock

Selection sort for Strings - 44352520 seconds CPU time. - 44 seconds wall clock

Selection sort for Strings - 47421951 seconds CPU time. - 47 seconds wall clock

Selection sort for Strings - 52596503 seconds CPU time.

Selection sort for Strings - 57022440 seconds CPU time. - 57 seconds wall clock

Selection sort for Strings - 64739546 seconds CPU time. - 65 seconds wall clock

Selection sort for Strings - 8.4247695E7 seconds CPU time. - 84.0 seconds wall clock

Selection sort for Strings - 85486091 seconds CPU time.

Selection sort for Strings - 86 seconds wall clock

Selection sort for Strings - 89961227 seconds CPU time.

Selection sort for Strings - 90 seconds wall clock

Selection sort for Strings - 93555451 seconds CPU time.

Selection sort for Strings - 94 seconds wall clock

Selection sort for Strings -33841883 seconds CPU time 33 seconds wall clock

T

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

This is the output file for the results

U

V

W

X

Y

Y

Z

Z

There are 352 words in the list

There are 17 numbers in the list

Selection sort for Strings - 0.42744712 seconds CPU time.

Selection sort for Integers - 2.22078E-4 seconds CPU time.

Bubble sort for String - 0.024927214 seconds CPU time.

Bubble sort for Integers - 2.686E-4 seconds CPU time.

Collection sort for Strings - 0.003828429 seconds CPU time.

Collection sort Integers - 6.4427E-5 seconds CPU time.

Selection sort for Strings - 0.042 seconds wall clock

Selection sort for Integers - 0.0 seconds wall clock

Bubble sort for String - 0.025 seconds wall clock

Bubble sort for Integers - 0.001 seconds wall clock

Collection sort for Strings - 0.004 seconds wall clock

Collection sort Integers - 0.0 seconds wall clock

Explanation / Answer

//the code is working fine now ... In String Every sorting printing strings.... that's it... check once now if you have any clarifications give me comment...

import java.util.*;

import java.io.*;

public class P5Sort {

private ArrayList<Integer> listInt; // List of integer numbers

private ArrayList<String> stringList; //List of String words

private String fileName; // File name for the Output file

private String outputString; // Output String

private String outputFile; // File name for the Output file

private final String LS = System.lineSeparator();

private Scanner scan;

private long startSystemTime; // CPU clock startindg time for int

private long endSystemTime; // CPU clock starting time for float

private long startTime; // Wall clock starting time for int

private long endTime;

private double cpuTimeSelectionSort;

private double cpuTimeBubbleSort;

private double cpuTimeCollection;

private double cpuTimeSelectionSortInt;

private double cpuTimeBubbleSortInt;

private double cpuTimeCollectionInt;

private double wallClockSelectionSort;

private double wallClockBubbleSort;

private double wallClockCollectionSort;

private double wallClockSelectionSortInt;

private double wallClockBubbleSortInt;

private double wallClockCollectionSortInt;

public P5Sort() {

listInt = new ArrayList<Integer>();

stringList = new ArrayList<String>();

fileName = null;

outputFile = "P5Output.txt";

scan = new Scanner(System.in);

}

public static void main(String[] args) {

P5Sort sort = new P5Sort();

sort.timingSots();

}

public void timingSots() {

System.out.println("Please enter a valid Input file name that have Words and also with .txt ... ");

fileName = scan.nextLine();

readTheFilesForString();

System.out.println("Please enter a valid Input file name that have Numbers and also with .txt ... ");

fileName = scan.nextLine();

readTheFilesForInt();

// Timing selction sort for an Arralist of String

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

selectionSort();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockSelectionSort = (double) (endTime - startTime) / 1000.0;

cpuTimeSelectionSort = (double) (endSystemTime - startSystemTime) / 100000000.0;

// Timing bubble sort for an Arralist of Strings

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

bubbleSort();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockBubbleSort = (double) (endTime - startTime) / 1000.0;

cpuTimeBubbleSort = (double) (endSystemTime - startSystemTime) / 1000000000.0;

// Timing collection sort in an Arraylist of Strings

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

collectionSortString();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockCollectionSort = (double) (endTime - startTime) / 1000.0;

cpuTimeCollection = (double) (endSystemTime - startSystemTime) / 1000000000.0;

// Timing selction sort for an Arraylist of Integers

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

selectionSortInt();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockSelectionSortInt = (double) (endTime - startTime) / 1000.0;

cpuTimeSelectionSortInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

// Timing bubble sort for an Arraylist of Integers

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

bubbleSortInt();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockBubbleSortInt = (double) (endTime - startTime) / 1000.0;

cpuTimeBubbleSortInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

// Timing selection sort for an Arraylist of Integers

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

selectionSortInt();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockSelectionSortInt = (double) (endTime - startTime) / 1000.0;

cpuTimeSelectionSortInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

// Timing collection sort for an Arraylist of Integers

startTime = System.currentTimeMillis();

startSystemTime = System.nanoTime();

collectionSort();

endTime = System.currentTimeMillis();

endSystemTime = System.nanoTime();

wallClockCollectionSortInt = (double) (endTime - startTime) / 1000.0;

cpuTimeCollectionInt = (double) (endSystemTime - startSystemTime) / 1000000000.0;

outputToFile();

}// end of mainMenu

public void selectionSort() {

int minValue = 0;

int startScan;

int index;

String temp;

for (startScan = 0; startScan < stringList.size(); startScan++) {

stringList.set(minValue, stringList.get(startScan));

for (index = startScan + 1; index < stringList.size(); index++) {

if ((stringList.get(index)).compareToIgnoreCase(stringList.get(startScan)) < 0) {

temp = stringList.get(startScan);

stringList.set(startScan, stringList.get(index));

stringList.set(index, temp);

}

}

//System.out.println(stringList.get(startScan));

}

}// end of selection sort

public void selectionSortInt() {

int minValue = 0;

int startScan;

int index;

int temp;

for (startScan = 0; startScan < listInt.size(); startScan++) {

listInt.set(minValue, listInt.get(startScan));

for (index = startScan + 1; index < listInt.size(); index++) {

if ((listInt.get(index)) < (listInt.get(startScan))) {

temp = listInt.get(startScan);

listInt.set(startScan, listInt.get(index));

listInt.set(index, temp);

}

}

//System.out.println(stringList.get(startScan));

}

}// end of selectionSortInt

public void bubbleSort() {

int startScan;

int index;

String temp;

for (startScan = 0; startScan < stringList.size(); startScan++) {

for (index = startScan + 1; index < stringList.size(); index++) {

if ((stringList.get(index)).compareToIgnoreCase(stringList.get(startScan)) < 0) {

temp = stringList.get(startScan);

stringList.set(startScan, stringList.get(index));

stringList.set(index, temp);

}

}

//System.out.println(stringList.get(startScan));

}

}// end of bubbleSort

public void bubbleSortInt() {

int startScan;

int index;

int temp;

for (startScan = 0; startScan < listInt.size(); startScan++) {

for (index = startScan + 1; index < listInt.size(); index++) {

if ((listInt.get(index)) < (listInt.get(startScan))) {

temp = listInt.get(startScan);

listInt.set(startScan, listInt.get(index));

listInt.set(index, temp);

}

}

//System.out.println(stringList.get(startScan));

}

}// end of bubbleSortInt

public void collectionSort() {

Collections.sort(listInt);

}

public void collectionSortString() {

Collections.sort(stringList);

}

public void readTheFilesForString() {

String content = new String();

File file = new File(fileName);

try {

Scanner sc = new Scanner(new FileInputStream(file));

while (sc.hasNextLine()) {

content = sc.nextLine();

stringList.add(content);

}

sc.close();

} catch (FileNotFoundException fnf) {

System.out.println("File not found.");

System.exit(0);

}

catch (Exception e) {

System.out.println(" Program terminated Safely...");

}

}// end of readTheFilesForString

public void readTheFilesForInt() {

int integerContent = 0;

File file = new File(fileName);

try {

Scanner sc = new Scanner(new FileInputStream(file));

while (sc.hasNextLine()) {

integerContent = sc.nextInt();

listInt.add(integerContent);

}

sc.close();

} catch (FileNotFoundException fnf) {

System.out.println("File not found.");

System.exit(0);

}

catch (Exception e) {

System.out.println(" Program terminated Safely...");

}

}// end of readTheFilesForInt

/**

* Prints the report with the data from the trial

*/

public void outputToFile() {

outputString = "There are " + stringList.size() + " words in the list" +

LS + "There are " + listInt.size() + " numbers in the list " +

LS + "Selection sort for Strings " + "- " + cpuTimeSelectionSort + " seconds CPU time. " +

LS + "Selection sort for Integers " + "- " + cpuTimeSelectionSortInt + " seconds CPU time. " +

LS + "Bubble sort for String " + "- " + cpuTimeBubbleSort + " seconds CPU time. " +

LS + "Bubble sort for Integers " + "- " + cpuTimeBubbleSortInt + " seconds CPU time. " +

LS + "Collection sort for Strings " + "- " + cpuTimeCollection + " seconds CPU time. " +

LS + "Collection sort Integers " + "- " + cpuTimeCollectionInt + " seconds CPU time. " +

LS + "Selection sort for Strings " + "- " + wallClockSelectionSort + " seconds wall clock " +

LS + "Selection sort for Integers " + "- " + wallClockSelectionSortInt + " seconds wall clock " +

LS + "Bubble sort for String " + "- " + wallClockBubbleSort + " seconds wall clock " +

LS + "Bubble sort for Integers " + "- " + wallClockBubbleSortInt + " seconds wall clock " +

LS + "Collection sort for Strings " + "- " + wallClockCollectionSort + " seconds wall clock " +

LS + "Collection sort Integers " + "- " + wallClockCollectionSortInt + " seconds wall clock "

+ LS + LS;

System.out.println(outputString);

writeReport(outputString);

}// end of outputToFile

/**

* Writes the report with the data from the trial

*/

private void writeReport(String reportString) {

try {

BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outputFile), true));

writer.write(reportString);

writer.close();

} catch (Exception ex) {

System.out.println("try a different file name");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote