4. File Review

Part 1. Find the 5 errors in the following code. You may wish to run the code.

Assume that the input file looks like this:

price file:
12
23
34
98

Assume that the output file looks like this:

after tax file:
$12 * 15% tax = total of $13.79
$23 * 15% tax = total of $26.45
$34 * 15% tax = total of $39.09
$98 * 15% tax = total of $112.69

The code:

import java.io.*;

public class errors
{

static final String priceFile = "price.txt";
static final String afterTaxFile = "afterTax.txt";

public static void main (String args [])
{

int a [] = new int [4];
load (priceFile, a);
save (afterTaxFile, a);

}

public static void save (String filename, int a [])
{

PrintWriter out;

try

//get ready to write to a file
out = new PrintWriter ();
//output the elements of the vector to the file

for (int i = 0 ; i < a.length ; i++)
{

out.println (a [i] + " * 15% tax = total of " + (a [i] * 1.15));

}
out.println ();

}
catch (IOException e)
{
   System.out.println ("Error opening file " + e);
}

}

public static void load (String filename, int a [])
{

BufferedReader in;
try
{

in = new BufferedReader (new FileReader (filename));
String input = in.readLine (); //read in line one
int i = 0;
//loop until end of file, read in data
while (input != null)
{

a [i] = Integer.parseInt (input);
input = in.readLine ();

}
in.close ();

}

}

}

Part 2. Write a program that gets a fie (picture.txt) and substitutes these symbols for the numbers found there. 

The correct solution will generate a picture on the screen.

1 - enter (new line)
2 - /
3 - \
4 - | or symbol
5 - _ underscore
6 - " quotes
7 - ' apostrophe
8 - . period
9 -   space