Nightocoder201 30 Newbie Poster

Hello,

I am working a program that starts at a direction and goes to the destination and reverse. I have reversed the list and used a if statement for the switching the directions from R (Right) and L (Left) but it doesnt want to work properly. My question is how can I make it work?

Thank you

import java.io.FileInputStream;
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

public class Project3 {

  public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    System.out.print("Enter input file name");
    String inFileName = in.nextLine();

    String[] parsedName = inFileName.split("\\.");
    String outFileName = parsedName[0] + "Numbered." + parsedName[1];

    String[]directions = {"R","L"};

    if (directions[i].equals("L")) {
      newDirection = "R";
    } else {
      newDirection = "L";
    }

    try {
      Scanner fIn = new Scanner(new FileInputStream(inFileName));
      PrintWriter fOut = new PrintWriter(new FileOutputStream(outFileName));

      int lineNumber = 0;
      while (fIn.hasNext()) {
        String line = fIn.nextLine();
        lineNumber++;
      }

      int lineNumber2 = 20;
      String[] reverse = new String[20];

       while (fIn.hasNext()) {
        String line = fIn.nextLine();
        reverse[lineNumber] = line;
        lineNumber++;

      }
        for (int i = 0; i < reverse.length; i++) { //Reversing the list
        fOut.println(reverse[(reverse.length-1)-i]);

      }

      fOut.close();
      fIn.close();
      fOut.close();

    } catch (FileNotFoundException e) {
      System.err.println("File " + inFileName + " not found");
    }
    }
  }

Here is the text file that I need to change the directions:

Start at Home
R on College Ave
L on Jefferson Davis Hwy
R on Cowan Blvd
R on Carl D Silver Pkwy
Qdoba on R

And this is the output of the file:

Start at Qdoba
L on Carl D Silver Pkwy
L on Cowan Blvd
L on Jefferson Davis Hwy
R on College Ave
Home on L