ok guys so i have problem here is the goal of this program:Write a Java program that reads in this file and produces a visual representation of the seat assignments, with a passenger's name and his/her seat assignment in each seat slot
here is the data in this text file:

rows 7
      leftSeats 1
      rightSeats 2
      1-B-L.Bleriot 1-C-A.Earhart
      2-B-W.Post 2-C-H.Hughes
      1-A-C.Lindbergh
      2-A-H.Quimby
      6-C-G.Curtiss
      4-C-K.Tank 4-B-B.Hoover

i need it to look like this :

A                      B                 C        
     1 [ C.Lindbergh 1A]      [   L.Bleriot 1B] [   A.Earhart 1C]
     2 [    H.Quimby 2A]      [      W.Post 2B] [    H.Hughes 2C]
     3 [               ]      [               ] [               ]
     4 [               ]      [    B.Hoover 4B] [      K.Tank 4C]
     5 [               ]      [               ] [               ]
     6 [               ]      [               ] [   G.Curtiss 6C]
     7 [               ]      [               ] [               ]

here is my code i have thus far:
passenger Class:

public class Passenger
{
    private String name;
    private int row;
    private char seat;

    public Passenger(String name, int row, char seat)
    {
        this.name = name;
        this.row = row;
        this.seat = seat;
    }

    Passenger(String[] name, String[] row, String[] seat) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
    @Override
    public String toString()
    {
        return name + " " + row + seat;
    }
}

here is my main class and the problem:

import static java.lang.System.out;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner reader;

        out.println("Welcome to Plane Talk ...");
        out.println("\ta program to display a passenger seating arrangement. ");

        reader = new Scanner(new FileInputStream("seats.txt"));
        while (reader.hasNext()) {
            // Read number of rows
            // Read number of seats

            int rows = reader.nextInt();
            int seats = reader.nextInt();

            // Initialize the 3 parallel arrays 

            String[] row = reader.next().split("-");
            String[] seat = reader.next().split("-");
            String[] name = reader.next().split("-");

            // read and split data
          
            Passenger pas = new Passenger(name, row, seat);


            // Place in appropriate list


            // print output header
            out.print(seats);
            // loop for i going from 1 to number of rows

            for (int i = 1; i < rows; i++) {

                out.format("[%15s]", pas.toString(), i);
            }
        }
        // print the three lists, position i


    }

// end of for loop

Problems:
1) i can't get past the first read loop i am getting this error

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at csc212project03b.Main.main(Main.java:26)
Java Result: 1

2) i having trouble // Placing in appropriate list
3) i sure there will be more

if you guys can point me in the right direction that would be much appreciated!!
thanks guys :)

1) You're only reading two ints before you start trying to read and parse strings - how does that match up with your input file?
2) After you've correctly parsed the passenger entry, you know which row and seat to put him in because it is stated as the first two pieces of data.

hey Ezzaral thanks for your response bro!
i understand you second point but still confused about your first statement

my input file's first 3 lines are

rows 7
leftSeats 1
rightSeats 2

so i want to read the 7 and have the scanner recognize that there will be 7 rows then read how many seats there will be (3 in total)
so would i have to do something like this:

int rows = reader.nextInt();
int leftSeats = reader.nextInt();
int rightSeats = reader.nextInt();

then i want to read the rest of the file and parse it up into the 3 arrays i declared? sorry if im not clear i sure its just a small thing i am missing :p

You will probably need to split the first three lines to separate the tags from the numbers before you read them. "rows 7" is not an integer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.