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);
}
}
}
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);
}
}
}
This is a JAVA language The files provided in the code editor to the right contain...
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: DebugDataOne1.txt and DebugDataOne2.txt do not need to be edited. They are used by the program. import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1.txt"); // path to file DebugDataOne1.txt in...
Need help debugging DebugThirteen1.Java Debug 13-1 DebugThirteen1.Java // Program describes two files // tells you which one is newer and which one is larger import java.nio.file.*; import java.nio.file.attribute.*; import java.io.IOException; public class DebugThirteen1 { public static void main(String[] args) { Path file1 = Paths.get("/root/sandbox/DebugDataOne1"); Path file2 = Paths.get("/root/sandbox/DebugDataOne2.txt"); try { BasicFileAttributes attr1 = Files.readAttributes(file1, BasicFileAttributes.class); System.out.println("File: " + file1getFileName()); System.out.println("Creation time " + attr1.creationTime()); System.out.println("Last modified time " + attr1lastModifiedTime()); System.out.println("Size " + attr1.size()); BasicFileAttributes attr2 = Files.readAttributes(file2, BasicFileAttributes.class); System.out.println("\nFile:...
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 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 each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. public class DebugTwo1 { public static void main(String[] args) { integer oneInt = 315; double oneDouble = 12.4; character oneChar = 'A'; System.out.print("The int is "); System.out.println(oneint); System.out.print("The double is "); System.out.println(onDouble); System.out.print("The char is "); System.out.println(oneChar); } }
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 =...
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 <...
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...
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...
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...