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 :)