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

change the following codes: public class Assignment3 { /** * Use this template t

ID: 645752 • Letter: C

Question

change the following codes:

public class Assignment3 {


/**
* Use this template to complete assignment 3. Only the code found in
* the "createTriangles" method will be considered for grading
* (We are automating the testing for this assignment.
* DO NOT EDIT THE MAIN METHOD, except for the values of
* INPUT and OUTPUT
* @param args
*/
public static void main(String[] args)
{
// Change these according to your environment
final String INPUT = "C:/testFiles/in/goodInput1.txt";
final String OUTPUT = "C:/testFiles/out/triangles1.txt";

boolean status = Assignment3.createTriangles(INPUT, OUTPUT);

if (status)
{
   System.out.println("OK");
}
else
{
   System.out.println("Check your input or output files.");
}

}

/**
* This method will take the read integers from the provided input file location.
* For each integer pair, it will calculate the third side of the Pythagorean theorem.
* The third sides will be placed within the output file.
* If there is a problem with a integer pair, the word "ERROR" will be placed in the
* output file. If there is a problem with the input and output file IO, then the
* method will return false. Otherwise, the method returns true.
* @param inputFile The input file location.
* @param outputFile The output file location.
* @return True, unless there is a problem with the input or output file.
*
*/
public static boolean createTriangles(String inputFile, String outputFile)
{
// Place all your code here

return true;
}

// You may also add methods here
}

Requirment:

triangle:
a2 + b2 = c2
which can alternatively be written as:
c = ?(a2 + b2)
Most of this expression contains simple operators covered in Chapter 3. The one piece that

1) You will obtain the inputs of the program from a text file. 2) The input file will have the following format: There should be an even number of integers in the file. The first integer n each pair s the A side of the triangle, and the second integer is the B side of the triangle. There is no limit of the number of side-pairs your program will have to process. For each valid integer pair, calculate side C as a double and print it to the output file. 3) Your program will be written using the template provided on Blackboard. You must not alter the class or method headers. See the code comments for further details. We are using the template to automate the grading process. 4) The output of the program should be saved to a file. This file should only contain each side C of the triangle or the word ?ERROR? for each error your program encounters. If an error is found on the first of a pair, skip the integer and go to the next valid pair. When an error occurs, add the word ?ERROR? in the output file. 5) If there is a problem with the input or output files, output the following string to System.out (the console, not the output file). The return value of the c method should also return false. When the input and output files are valid, method should return true.

Explanation / Answer

/**
* The java program that reads a text file called
* goodInput1.txt file that contains pair of
* values of a triangles.
* Read each pair and find third side value
* and write to output file triangles1.txt.
* If value is exist for pair, then write
* an error message to the file.
* */
//Assignment3 .java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Assignment3
{
   /**
   * Use this template to complete assignment 3. Only the code found in
   * the "createTriangles" method will be considered for grading
   * (We are automating the testing for this assignment.
   * DO NOT EDIT THE MAIN METHOD, except for the values of
   * INPUT and OUTPUT
   * @param args
   * @throws FileNotFoundException
   */
   public static void main(String[] args) throws FileNotFoundException
   {
       // Change these according to your environment
       final String INPUT = "goodInput1.txt";
       final String OUTPUT = "triangles1.txt";

       //The method returns false if there is a error in INPUT or OUTPUT file
       //reading
       boolean status = Assignment3.createTriangles(INPUT, OUTPUT);

       if (status)
       {
           System.out.println("OK");
       }
       else
       {
           System.out.println("Check your input or output files.");
       }

   }

   /**
   * This method will take the read integers from the provided input file location.
   * For each integer pair, it will calculate the third side of the Pythagorean theorem.
   * The third sides will be placed within the output file.
   * If there is a problem with a integer pair, the word "ERROR" will be placed in the
   * output file. If there is a problem with the input and output file IO, then the
   * method will return false. Otherwise, the method returns true.
   * @param inputFile The input file location.
   * @param outputFile The output file location.
   * @return True, unless there is a problem with the input or output file.
   * @throws FileNotFoundException
   *
   */
   public static boolean createTriangles(String inputFile, String outputFile)
           throws FileNotFoundException
           {

       int sideA=0;
       int sideB = 0;
       Scanner fileReader=null;
       PrintWriter writer=new PrintWriter(outputFile);
       File inFile=null;
       boolean error=false;
       boolean ioerror=false;

       try
       {
           //open an file
           inFile=new File(inputFile);
           //Create file input stream of Scanner class
           fileReader=new Scanner(inFile);


           while(fileReader.hasNextInt())
           {
               //read sideA value
               sideA=fileReader.nextInt();
               //Then check for next int
               if(fileReader.hasNextInt())
                   //iF next is present then read
                   sideB=fileReader.nextInt();
               else
               {
                   //Otherwise
                   //write Error message if the file has two values to
                   //calculate sideC value
                   writer.println("ERROR");
                   error = true;
               }

               if(!error)
               {
                   double sideC=Math.sqrt(Math.pow(sideA, 2.0)+Math.pow(sideB, 2.0));
                   writer.println(sideC);
               }
           }

           //close the input and output file streams
           fileReader.close();
           writer.close();

       }
       catch (Exception e)
       {
           ioerror=true;
           System.out.println(e.getMessage());

       }

       return ioerror;
       }

   // You may also add methods here
}

-----------------------------------
Sample input file

goodinput1.txt file

91
32
73
62
78
11

-------------------------------------------
sample output:
triangles.txt

96.46242791885346
95.77577981932593
78.77182237323191

Note : input file must be in the current working directory .

Add extra value to the input file so that you get an errro in output file for that case.


Hope this could be helpful

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