Sorry the import statement must have gotten cut out somehow. I added some comments and I think I did some
java docs not quite sure if they are
Correct or not. Now I get a message saying
//airplaneSeating2.java:38: illegal start of type
// do
// ^
//airplaneSeating2.java:287: <identifier> expected
// while (resetOrCA != 'B');
// ^
//2 errors
/*
* Author: Dustin Schreader
*
* Date: 05082010
*
* Course: comp 2243 spring
*
* Assignment: Ch. 9 exercise #12 p606
*
* Description: Prompts user for seating that they prefer
* The user may choose from economy or first class
* If economy is chosen the user may choose smoking
* Or non smoking then may choose a seat from an array
* The array will be used by picking row numbers and
* Column letters, the user may choose to reset the
* Program or continue to choose a seat.
*
*/
import java.io.*;
import java.util.*;
/**
*
* Have the user decide which seat they would like to use
* Can choose a seat between smoking and non and economy
* Or first classe
*
* @author Dustin Schreader
* @version 05082010
*/
public class airplaneSeating2
{
static char resetOrCA = ' ';
do
{
//^ This is the start of the do while loop
// in order for the user to choose to reset
// the program or choose another seat
static BufferedReader keyboard = new
BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
static char [][] seatNumber =
{
{'*','*','X','*','X','X'},
{'*','X','*','X','*','X'},
{'*','*','X','X','*','X'},
{'X','*','X','*','X','X'},
{'*','X','*','X','*','*'},
{'*','x','*','*','*','X'},
{'X','*','*','*','X','X'},
{'*','X','*','X','X','*'},
{'X','*','X','X','*','X'},
{'*','X','*','X','X','X'},
{'*','*','X','*','X','*'},
{'*','*','X','X','X','X'},
{'*','*','*','*','X','*'},
};
/**
* prompts the user whether they want economy or first class
* then it prompts the user for smoking or non if economy
*
* @param args not used
*/
public static void main(String args[]) throws IOException
{
String inputStr;
char smokingType = ' ';
char classType;
int rowStart = 0;
int rowEnd = 0;
System.out.println(" #############################");
System.out.println(" # #");
System.out.println(" # Airplane Seating Program! #");
System.out.println(" # #");
System.out.println(" #############################");
System.out.println();
do
{
System.out.print("Enter Class Preference E for Econonmy, F for First Class: ");
inputStr = keyboard.readLine();
inputStr = inputStr.toUpperCase();
classType = inputStr.charAt(0);
System.out.println();
switch (classType)
{
case 'E':
do
{
System.out.print("Enter Smoking Preference S for Smoking, N for Non-Smoking: ");
inputStr = keyboard.readLine();
inputStr = inputStr.toUpperCase();
smokingType = inputStr.charAt(0);
System.out.println();
switch (smokingType)
{
case 'S':
rowStart = 8;
rowEnd = 13;
break;
case 'N':
rowStart = 3;
rowEnd = 7;
break;
default:
System.out.println("Invalid Input, Enter N - non smoking or S - smoking!");
System.out.println();
break;
}
}
while (smokingType != 'N' && smokingType != 'S');
break;
case 'F':
rowStart = 1;
rowEnd = 2;
break;
default:
System.out.println("Invalid Input, enter E - Economy or F - First Class!");
System.out.println();
break;
}
}
while (classType != 'F' && classType != 'E');
printMatrix(seatNumber, rowStart, rowEnd);
chooseSeat(seatNumber, rowStart, rowEnd);
printMatrix(seatNumber, 1, 13);
}
/**
* This method prints out the matrix for the user
* to view and see what seats are available to choose
* from
*
* @param args not used
*/
public static void printMatrix(char[][] matrix, int row1, int row2)
{
int col;
System.out.println();
System.out.println("Available Seats");
System.out.printf("%11s %4s %4s %4s %4s %4s", "A", "B", "C", "D", "E", "F");
System.out.println();
for (row1 = row1 - 1; row1 < row2; row1++)
{
System.out.printf("Row %2d", (row1 + 1));
for (col = 0; col < matrix[row1].length; col++)
{
System.out.printf("%5c", matrix[row1][col]);
}
System.out.println();
}
System.out.println();
System.out.println(" * indicates the seat is available");
System.out.println(" X indicates the seat is not available");
System.out.println();
}
/**
* @throws IOException if an input or output
* exception occured
*/
public static void chooseSeat(char[][] matrix, int row1, int row2) throws IOException
{
String inputStr;
String seat;
int row;
char col;
String colStr;
int colNo = 10;
do
{
System.out.println("To select a seat enter the row number: ");
inputStr = keyboard.readLine();
row = new Integer(inputStr);
System.out.println("Enter the column seat letter: ");
inputStr = keyboard.readLine();
colStr = inputStr.toUpperCase();
col = colStr.charAt(0);
System.out.println("Column: " + col);
switch(col)
{
case 'A': colNo = 0;
break;
case 'B': colNo = 1;
break;
case 'C': colNo = 2;
break;
case 'D': colNo = 3;
break;
case 'E': colNo = 4;
break;
case 'F': colNo = 5;
break;
default:
System.out.println("Invalid Input, Enter column A, B, C, D, E, F!");
System.out.println();
break;
}
}
while (col != 'A' && col != 'B' && col != 'C' && col != 'D' && col != 'E' && col != 'F');
// ^ lets the user choose seat row number and column letter until
// until user chooses correct letter, although if there is
// a number that is incorrect there is not a message sent out
// to user and the program exits with error
System.out.println("Row: " + row);
seatNumber[row -1][colNo] = 'X';
seat = row + colStr;
System.out.println("You chose: " + seat);
System.out.println("Thank you");
System.out.println();
}
System.out.print("Enter B to reset or O to choose another seat: ");
inputStr = keyboard.readLine();
inputStr = inputStr.toUpperCase();
resetOrCA = inputStr.charAt(0);
System.out.println();
// ^ This is used to prompt the user if they would like
// to choose another seat or reset and info s put into
// resetOrCA
}
while (resetOrCA != 'B');
//^ here is the while statement to decied whether
// to reset the seating assignment or choose another seat
// not sure how to reset the array matrix yet
}