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

I need this program according to Introduction to java programming book by Y. Dan

ID: 3632305 • Letter: I

Question

I need this program according to Introduction to java programming book by Y. Daniel Liang. Thanks.

CS213 Project 3
Task for Project 3
Project Objective:
• Effectively use the String, Character, and StringBuilder classes and associated methods
• Write Java code to read and write data to and from a file


Deliverables:
In this programming project the student will design, develop, test and document a Java application that reads data from an input file, processes the data, and then writes the processed data to an output file.

Projects submitted with evidence of plagiarism will be given a score of 0.
Your projects are due by midnight, EST, on the date posted in the class schedule. Your instructor's policy on late projects applies to this project.

Specific functional requirements for this project:

1. The application should be run from the command line using command line arguments to provide the input and output filenames.
2. The application should display an appropriate error message if the user forgets to enter the input and output filenames at the command prompt or if the files are not found.
3. The application should open the file and read each line of the file.
4. For each line read, the application should determine the total number of characters in the line (including white-space characters), determine the number of times the number 4 appears in the line, replace all occurrences of the string "this" with "That", and reverse the order of the characters in the line.
5. The output file should contain the same number of lines as the input file with the following content for each line:
a. Total number of characters (including white-space characters) in the line
b. Number of times the number 4 appeared in the line
c. Reversed string (for example, cats in the input file would be displayed as stac)

The items on each line in the output file should be separated by commas (for example: for input line "this4cats", the output line should be "9,1,stac4tahT")

6. The application should close any open files before exiting.

Format:

Code Documentation and Style Requirements
The documentation requirement for all programming projects is one block comment at the top of the program containing the course name, the project number, your name, the date and platform/compiler that you used to develop the project. In addition, there should be at least one comment for each class in the program describing what that class does. Additional comments should be provided as necessary to clarify the program.
Indentation must be consistent throughout the program. Variable and method names should be descriptive of the role of the variable or method. Single letter names should be avoided. All constants, except 0 and 1, should be named. Constant names should be all upper-case. Variable names should begin in lower-case, but subsequent words should be in title case (e.g., finalSpeed).
Separate compilation must be used in accordance with standard Java practice. Every class must be saved in a separate .java file

Before submitting the program, you should test and run it, and make sure it works properly. Submit your source code (the file with the extension .java), inputfile and outputfile to the Project 3 Folder.
WARNING: NEVER WRITES YOUR SOURCE CODE USING MICROSOFT WORD!
Instead, you should use either the editor come with the IDE or notepad.

Rubric for Project 3

60 total points possible.

(25 points) Carefully declare all the variables with appropriate data types. Use comments effectively to make the program more readable. Implement the calculations correctly.

(25 points) Compile and build the Java program. Test the program and make sure the program produces the desired answer.

(10 point) Submit your source code, algorithm, UML Diagrams and screenshots as an attached file to Project3 Folder


Explanation / Answer

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

public class FileUtil {

DataOutputStream dos;

/*
   * Utility method to write a given text to a file
   */
public boolean writeToFile(String fileName, String dataLine,
      boolean isAppendMode, boolean isNewLine) {
    if (isNewLine) {
      dataLine = " " + dataLine;
    }

    try {
      File outFile = new File(fileName);
      if (isAppendMode) {
        dos = new DataOutputStream(new FileOutputStream(fileName, true));
      } else {
        dos = new DataOutputStream(new FileOutputStream(outFile));
      }

      dos.writeBytes(dataLine);
      dos.close();
    } catch (FileNotFoundException ex) {
      return (false);
    } catch (IOException ex) {
      return (false);
    }
    return (true);

}

/*
   * Reads data from a given file
   */
public String readFromFile(String fileName) {
    String DataLine = "";
    try {
      File inFile = new File(fileName);
      BufferedReader br = new BufferedReader(new InputStreamReader(
          new FileInputStream(inFile)));

      DataLine = br.readLine();
      br.close();
    } catch (FileNotFoundException ex) {
      return (null);
    } catch (IOException ex) {
      return (null);
    }
    return (DataLine);

}

public boolean isFileExists(String fileName) {
    File file = new File(fileName);
    return file.exists();
}

public boolean deleteFile(String fileName) {
    File file = new File(fileName);
    return file.delete();
}

/*
   * Reads data from a given file into a Vector
   */

public Vector fileToVector(String fileName) {
    Vector v = new Vector();
    String inputLine;
    try {
      File inFile = new File(fileName);
      BufferedReader br = new BufferedReader(new InputStreamReader(
          new FileInputStream(inFile)));

      while ((inputLine = br.readLine()) != null) {
        v.addElement(inputLine.trim());
      }
      br.close();
    } // Try
    catch (FileNotFoundException ex) {
      //
    } catch (IOException ex) {
      //
    }
    return (v);
}

/*
   * Writes data from an input vector to a given file
   */

public void vectorToFile(Vector v, String fileName) {
    for (int i = 0; i < v.size(); i++) {
      writeToFile(fileName, (String) v.elementAt(i), true, true);
    }
}

/*
   * Copies unique rows from a source file to a destination file
   */

public void copyUniqueElements(String sourceFile, String resultFile) {
    Vector v = fileToVector(sourceFile);
    v = MiscUtil.removeDuplicates(v);
    vectorToFile(v, resultFile);
}

} // end FileUtil

class MiscUtil {

public static boolean hasDuplicates(Vector v) {
    int i = 0;
    int j = 0;
    boolean duplicates = false;

    for (i = 0; i < v.size() - 1; i++) {
      for (j = (i + 1); j < v.size(); j++) {
        if (v.elementAt(i).toString().equalsIgnoreCase(
            v.elementAt(j).toString())) {
          duplicates = true;
        }

      }

    }

    return duplicates;
}

public static Vector removeDuplicates(Vector s) {
    int i = 0;
    int j = 0;
    boolean duplicates = false;

    Vector v = new Vector();

    for (i = 0; i < s.size(); i++) {
      duplicates = false;
      for (j = (i + 1); j < s.size(); j++) {
        if (s.elementAt(i).toString().equalsIgnoreCase(
            s.elementAt(j).toString())) {
          duplicates = true;
        }

      }
      if (duplicates == false) {
        v.addElement(s.elementAt(i).toString().trim());
      }

    }

    return v;
}

public static Vector removeDuplicateDomains(Vector s) {
    int i = 0;
    int j = 0;
    boolean duplicates = false;
    String str1 = "";
    String str2 = "";

    Vector v = new Vector();

    for (i = 0; i < s.size(); i++) {
      duplicates = false;
      for (j = (i + 1); j < s.size(); j++) {
        str1 = "";
        str2 = "";
        str1 = s.elementAt(i).toString().trim();
        str2 = s.elementAt(j).toString().trim();
        if (str1.indexOf('@') > -1) {
          str1 = str1.substring(str1.indexOf('@'));
        }
        if (str2.indexOf('@') > -1) {
          str2 = str2.substring(str2.indexOf('@'));
        }

        if (str1.equalsIgnoreCase(str2)) {
          duplicates = true;
        }

      }
      if (duplicates == false) {
        v.addElement(s.elementAt(i).toString().trim());
      }

    }

    return v;
}

public static boolean areVectorsEqual(Vector a, Vector b) {
    if (a.size() != b.size()) {
      return false;
    }

    int i = 0;
    int vectorSize = a.size();
    boolean identical = true;

    for (i = 0; i < vectorSize; i++) {
      if (!(a.elementAt(i).toString().equalsIgnoreCase(b.elementAt(i)
          .toString()))) {
        identical = false;
      }
    }

    return identical;
}

public static Vector removeDuplicates(Vector a, Vector b) {

    int i = 0;
    int j = 0;
    boolean present = true;
    Vector v = new Vector();

    for (i = 0; i < a.size(); i++) {
      present = false;
      for (j = 0; j < b.size(); j++) {
        if (a.elementAt(i).toString().equalsIgnoreCase(
            b.elementAt(j).toString())) {
          present = true;
        }
      }
      if (!(present)) {
        v.addElement(a.elementAt(i));
      }
    }

    return v;
}

}// end of class

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