1

So here's the problem: File gets created, first line of text gets written, but the text within the logic loop of for>if>while doesn't write: PassengerSeats.println(nRowNum +cSeatLetter +" " +sPassengerName);

Here's the main method code in question:

else if (nMainChoice == 4) {
    System.out.print("Please enter a flight number: ");
    nMainFlight = input.nextInt();
    input.nextLine();
    System.out.println("Please enter a date of departure: ");
    System.out.print("Month: (i.e For January, enter 1): ");
    sMonth = input.nextLine();
    System.out.print("Day: (i.e for the 15h, enter 15): ");
    sDay = input.nextLine();
    System.out.print("Year: (i.e for 2015, enter 15): ");
    sYear = input.nextLine();
    sDate = sMonth +"/" +sDay +"/" +sYear;
    System.out.println(sDate);

    PrintManifest newManifest = new PrintManifest(TicketsList,
                    FlyersList, nMainFlight, sDate, sMonth, sDay, sYear);

And here's the PrintManifest code it refers to:

public PrintManifest(ArrayList<Tickets> TicketsListing, ArrayList<Flyers> FlyersListing, 
        int nFlightID, String sFlightDate, String sFMonth, String sFDay, 
        String sFYear) throws Exception{

    String sFlightManifest = "DataFiles/Manifest-nFlightID-sFMonth-sFDay-sFYear.txt";
    File FlightManifest = new File(sFlightManifest);
    PrintWriter PassengerSeats = new PrintWriter(FlightManifest);

    PassengerSeats.println("Flight manifest for #" +nFlightID +" on " +sFlightDate);

    for (nCount = 0; nCount < TicketsListing.size(); nCount++) {
        if (nFlightID == TicketsListing.get(nCount).getFlightNumber() 
            && sFlightDate == TicketsListing.get(nCount).getDate()) {

        nRowNum = TicketsListing.get(nCount).getRow();
        cSeatLetter = TicketsListing.get(nCount).getSeat();

        while (TicketsListing.get(nCount).getFlyerID() != FlyersListing.get(nCountFly).getID()) {
            nCountFly++;
        } //End while loop

        sPassengerName = FlyersListing.get(nCountFly).getFirst() +" " 
                +FlyersListing.get(nCountFly).getLast();

        PassengerSeats.println(nRowNum +cSeatLetter +" " +sPassengerName);
        } //End if 
    } //End for loop

    PassengerSeats.close();

And a sample of the data it's pulling from TicketsList, which is already parsed and stored within an arraylist:

19836;1258;1359;1/2/15;A;5;A
19837;1215;1359;1/2/15;A;6;C
19838;1245;438;1/11/15;M;15;F
19839;1129;1014;1/5/15;M;17;F
19840;1139;703;1/11/15;M;14;C
19841;1353;689;1/11/15;F;3;D
19842;1296;1014;1/2/15;F;4;F
4
  • Is it possible that the file you are trying to write to doesn't exist or has different permissions? Commented Apr 17, 2015 at 19:41
  • What does PassengerSeats.println do? Commented Apr 17, 2015 at 19:45
  • If the file doesn't exist, it will be created, and if it exists, it will be overwritten. That's how printwriter works, so it definitely exists and is created successfully. And it's not a permissions problem. Using everything as admin. Commented Apr 17, 2015 at 19:45
  • PassengerSeats.println(); writes whatever i put into the parenthesis to the text file, much like System.out.println(); Commented Apr 17, 2015 at 19:46

1 Answer 1

3

The boolean expression

sFlightDate == TicketsListing.get(nCount).getDate()

will always evaluate to false, which means nothing in your if statement will execute. The equals method should be used to evaluate string equality, like this

sFlightDate.equals(TicketsListing.get(nCount).getDate())

because it compares the contents of the strings. The == operator compares the object pointer, which will always be different in this case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.