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

Suppose you are given a text file words2.txt. It contains a set of words. Your t

ID: 3752814 • Letter: S

Question

Suppose you are given a text file words2.txt. It contains a set of words. Your task is to read the words from the file, sort them alphabetically using algorithm, and create a file for sorted words called sorted.txt. Also report to the console how many swap operations it required for the sorting.(Using Java) this code work but i am trying use bubble sort i am having problem.

MY Work

import java.io.*;

import java.util.*;

public class sort {

   private static final String filename = "sorted.txt";

   public static void main(String[] args) {

       BufferedReader rd = null;

       try {

           // Open the file for reading.

           rd = new BufferedReader(new FileReader(new File(filename)));

           // Read all contents of the file.

           String inputLine = null;

           while((inputLine = rd.readLine()) != null)

               System.out.println(inputLine);

       }

       catch(IOException ex) {

           System.err.println("An IOException was caught!");

           ex.printStackTrace();

       }

       finally {

           try {

               rd.close();

           }   catch (IOException ex) {

               System.err.println("An IOException was caught!");

               ex.printStackTrace();

           }

       }

   }

}

Explanation / Answer

import java.io.*; import java.util.*; public class sort { public static void bubbleSort(ArrayList list) { for (int i = 1; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote