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

Hey, Please help me coding the below program: Test case and Junit test is provid

ID: 670227 • Letter: H

Question

Hey, Please help me coding the below program: Test case and Junit test is provided below.

IO Practice file:

import java.io.*;
import java.util.*;

/**
* Some practice with file I/O.
*/
class IOPractice {
   /**
   * An example main method to test functionality.
   */
   public static void main(String[] args) {
       if(args.length != 2) {
           System.out.println("Two command line argument required: (1) input file name (2) output file name");
       }
       else {
           String result1 = IOPractice.readFromFile(args[0]);
           IOPractice.writeToFile(args[1], result1);
           String result2 = IOPractice.readFromFile(args[1]);
           if(result1.equals(result2)) {
               System.out.println("Win!");
           }
           else {
               System.out.println("Not working yet :(");
           }
       }
   }
}

Junit testing

//test readFromFile() returns null on error
   @Test(timeout=2000)
   public void practice02() {
       assertNull(IOPractice.readFromFile("banana")); //assumes file "banana" doesn't exist

   }


   //test readFromFile() returns false on error
   @Test(timeout=2000)
   public void practice03() {
       assertFalse(IOPractice.writeToFile("????", "")); //invalid file name
   }
  
   //run the test file
   public static void main(String args[]) {
       org.junit.runner.JUnitCore.main("Assignment2SampleTests");
   }

Step 1: Read Input Create a method called readFromFile) that accepts a file name and returns the contents of the file as a String. If an exception occurs, return null instead Step 2: Print Output Create a method called writeToFileO that accepts a file name and the text to export print to the file. If you are able to print to the file, return true. If an exception occurs, return false Testing 1. IOPractice.java - A main method has been provided. Do not edit this method to make your code 2. Assignment2SampleTests.java - provides test cases in JUnit format. These tests can be run 3. An example run of this program would look like: work using the same methods shown in Lab 01 javac *.java Java IOPractice ·/text/example11n.txt output.txt Win

Explanation / Answer

import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.Reader; import java.util.ListIterator; import java.util.Vector; public class IOpractice { public static void main(String[] args) { Vector lines = new Vector(); try { BufferedReader in = new BufferedReader(new FileReader("src/practice.txt")); String s = new String(); while((s=in.readLine())!= null){ lines.add(s); } in.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e){ } try{ PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/b.txt"))); ListIterator it = lines.listIterator(lines.size()); String s,t; while(it.hasPrevious()){ s = (String)it.previous(); t = s.toUpperCase(); System.out.println("IOpractice.main() :" + t); int i = 1; out.write("Line"+i+" "+ s +" "); } out.close(); }catch(Exception e){ } } }