Hello,
Is it possible for anyone to explain to me what
"Initialize the 3 parallel arrays" means?
Here is the problem.
A file called seats.txt contains a description of an airline seating arrangement and a list of individual seat assignments. An example is shown here:
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
This example indicates a plane has 7 rows. In a given row, there is 1 seat on the left and 2 seats on the right separated by an aisle. 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. The above example would produce the following output:
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 [ ] [ ] [ ]
Notice the space representing the aisle between seats A and seats B and C.
To keep things manageable, the airplane will always have 3 seats, either 1 on the left and two on the right, or 2 on the left and 1 on the right. Hints:
Use the "split()" method in the Java String class to split the assignment string into a row, seat, and passenger name.
Use the System.out.format() method to produce fixed width "cells" for each seat. For example, the
out.format("[%15s]", passenger.toString());
produces space for 15 characters in a passenger's name.
You can use either a 2-dimensional array or three parallel arrays to make the task easier.
Here is a main class to start with.
Here is a Passenger.java class which can be used.
HERE IS THE CODE for the Main Class
package csc212project03b;
/**
* File: Main.java
*/
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"));
// Read number of rows
// Read number of seats
// Initialize the 3 parallel arrays (or 1 2-D array)
while ( reader.hasNext() ) {
// read and split data
// once you have the data, uncomment next line
// Passenger pas = new Passenger(name, row, seat);
// Place in appropriate list
}
// print output header
// loop for i going from 1 to number of rows
// print the three lists, position i
// end of for loop
}
}
OTHER CLASS
package csc212project03b;
/**
* File: Passenger.java
*/
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;
}
public String toString()
{
return name + " " + row + seat;
}
}
I just gave you the whole assignment that way if it was needed to explain to me how I would initialize the 3 parallel array. Just looking for help or a hint. I don't want the whole answer as I am supposed to learn from this, but I have no idea how to initialize the 3 parallel arrays. Thanks.