Question

This is a JAVA language The files provided in the code editor to the right contain...

This is a JAVA language

The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.

Note: DebugData2.txt does not need to be edited. It is used by the program.

DebugData2.txt

435-9845
239-9845
981-9883
384-5656
875-3784
874-8120

DebugThirteen2.java

// Program reads in a file of phone numbers without area codes
// inserts "(312) " in front of each phone number
// and produces an output file with the new complete phone numbers
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
public class DebugThirteen2
{
public static void main(String[] args)
{
Path fileIn =
Paths.get("/root/sandbox/DebugData2.txt");
Path fileOut =
Paths.get("/root/sandbox/DebugData2New.txt");
String areaCode = "(312) ";
String phone;
InputStream input = nul;
OutputStream output = nul;
try
{
input = Files.newInputStream(fileIn);
BufferedReader reader = BufferedReader
(new InputStreamReader(input));
output = Files.newOutputStream(fileOut);
phone = reader.readLine();
while(phone = null)
{
phone = areaCode + phone + System.getProperty("line.separator");
byte phoneBytes = phone.getBytes();
output.write(phoneBytes);
phone = reader.readline();
}
input.closes();
output.closes();
}
catch (IOException e)
{
System.out.println(e);
}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Given below is the fixed code for the question. Please do rate the answer if it helped. Thank you.


// Program reads in a file of phone numbers without area codes
// inserts "(312) " in front of each phone number
// and produces an output file with the new complete phone numbers
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import static java.nio.file.StandardOpenOption.*;
public class DebugThirteen2
{
   public static void main(String[] args)
   {
       Path fileIn =
               Paths.get("/root/sandbox/DebugData2.txt");
       Path fileOut =
               Paths.get("/root/sandbox/DebugData2New.txt");
      
       String areaCode = "(312) ";
       String phone;
       InputStream input = null;
       OutputStream output = null;
       try
       {
           input = Files.newInputStream(fileIn);
           BufferedReader reader = new BufferedReader
                   (new InputStreamReader(input));
           output = Files.newOutputStream(fileOut);
           phone = reader.readLine();
           while(phone != null)
           {
               phone = areaCode + phone + System.getProperty("line.separator");
               byte[] phoneBytes = phone.getBytes();
               output.write(phoneBytes);
               phone = reader.readLine();
           }
           input.close();
           output.close();
       }
       catch (IOException e)
       {
           System.out.println(e);
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
This is a JAVA language The files provided in the code editor to the right contain...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // DebugFive2.java // Decides if two numbers are evenly divisible import java.util.Scanner; public class DebugFive2 { public static void main(String args[]) { int num; int num2; Scanner input = new Scanner(System.in); System.out.print("Enter a number "); num = input.nextInteger() System.out.print("Enter another number ");...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Prompt user for value to start // Value must be between 1 and 20 inclusive // At command line, count down to blastoff // With a brief pause between each displayed value import java.util.*; public class DebugSix3 { public static void...

  • The files provided in the code editor to the right contain syntax and/or logic errors. In...

    The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 { public static void main(String args[]) { final int DAYS = 30; double money = 0.01; int day =...

  • /************************************************************************* * Compilation: javac JavaLab1.java * Execution: java JavaLab1 * Authors: Odile wolf, Olusola Samuel-Ojo *...

    /************************************************************************* * Compilation: javac JavaLab1.java * Execution: java JavaLab1 * Authors: Odile wolf, Olusola Samuel-Ojo * Date created: Jan 15th 2014 * Last update date: Sep 13th 2017 * You will modify the code to ask the user for their age and the age of their child, and output how old the mother * was when the child was born * % java JavaLab1 * What is your name ? Jane * Jane, what is your age? 30 * What...

  • Q22 Consider the following 2 text files and Java program. 8 Points Answer the following questions...

    Q22 Consider the following 2 text files and Java program. 8 Points Answer the following questions keeping in mind that: • All three files are in the same directory, and there are no other files. • The program may crash. If the program crashes, answer the question with: "The program crashes" standings1.txt: 1 Valtteri Bottas 25 2 Charles Leclerc 18 3 Lando Norris 16 4 Lewis Hamilton 12 standings2.txt: 1 Valtteri Bottas 43 2 Lewis Hamilton 37 3 Lando Norris...

  • The files provided contain syntax and/or logic errors. In each case, determine and fix the problem,...

    The files provided contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. import java.util.*; public class DebugEight1 { public static void main(String args[]) { Scanner input = new Scanner(System.in); char userCode; String entry, message; boolean found = false; char[] okayCodes = {'A''C''T''H'}; StringBuffer prompt = new StringBuffer("Enter shipping code for this delivery\nValid codes are: "); for(int x = 0; x <...

  • composed the following java code to read a string from a text file but receiving compiling...

    composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main {   public static void main(String[] args) {     System.out.print("Enter the...

  • The names of the two input files as well as the output file are supposed to be provided as arguments. Could you please fix it? Thanks. DPriorityQueue.java: // Import the required classes import java....

    The names of the two input files as well as the output file are supposed to be provided as arguments. Could you please fix it? Thanks. DPriorityQueue.java: // Import the required classes import java.io.*; import java.util.*; //Create the class public class DPriorityQueue { //Declare the private members variables. private int type1,type2; private String CostInTime[][], SVertex, DVertex; private List<String> listOfTheNodes; private Set<String> List; private List<Root> ListOfVisitedNode; private HashMap<String, Integer> minimalDistance; private HashMap<String, Integer> distOfVertices; private PriorityQueue<City> priorityQueue; // prove the definition...

  • Creating a Shell Interface Using Java This project consists of modifying a Java program so that...

    Creating a Shell Interface Using Java This project consists of modifying a Java program so that it serves as a shell interface that accepts user commands and then executes each command in a separate process external to the Java virtual machine. Overview A shell interface provides the user with a prompt, after which the user enters the next command. The example below illustrates the prompt jsh> and the user’s next command: cat Prog.java. This command displays the file Prog.java on...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT