gladly
/*
JOEL JOHNSON
Project #3 : AIRLINE RESERVATIONS
*/
import chn.util.*;
import apcslib.*;
class START
{
public static void main(String[] args)
{
MENU execute = new MENU();
execute.control();
}
}//END OF CLASS
class passenger
{
private String Lastname;
private String Firstname;
private String Midinitial;
private String Column;
private int row;
passenger(String Lname, String Fname, String Minitial)
{
Lastname = Lname;
Firstname = Fname;
Midinitial = Minitial;
}
public void assignseat(int x, int y)
{
if (x==0)
Column = "A";
if (x==1)
Column = "B";
if (x==2)
Column = "C";
if (x==3)
Column = "D";
row = (y+1);
}
public String getLastname()
{
return Lastname;
}
public String getFirstname()
{
return Firstname;
}
public String getMidinitial()
{
return Midinitial;
}
}//END OF CLASS
//everything to do with arrays are stored in here\
class ARRAYSTUFF
{
ConsoleIO console = new ConsoleIO();
public int xpos = -1;
public int ypos = -1;
//declare the array "flight" as a type of passenger with the size of 4x50
passenger[][] flight = new passenger[4][50];
//fills the array with 0's
public void init()
{
for(int x = 0; x < 4; x++)
for (int y = 0; y < 50; y++)
{
flight[x][y] = new passenger("0","0","0");
flight[x][y].assignseat(x,y);
}
}
//Creates the method to save the array in "flightdata.txt"\
public void save()
{
FileOutput outfile = new FileOutput("flightdata.txt");
for(int y = 0; y < 50; y++)
for(int x = 0; x < 4; x++)
{
outfile.println(flight[x][y].getLastname());
outfile.println(flight[x][y].getFirstname());
outfile.println(flight[x][y].getMidinitial());
}
outfile.close();
}
//Creates the method to load the array from "flightdata.txt\
public void retrieve()
{
String TLname;
String TFname;
String TMid;
FileInput infile = new FileInput("flightdata.txt");
for(int y = 0; y < 50; y++)
for(int x = 0; x < 4; x++)
{
TLname = infile.readToken();
TFname = infile.readToken();
TMid = infile.readToken();
flight[x][y] = new passenger(TLname, TFname, TMid);
flight[x][y].assignseat(x,y);
}
infile.close();
}
public int NewReservation()
{
int classtype = 0;
int seatcolumn = 0;
int x1 = 0;
int x2 = 0;
int y1 = 0;
int y2 = 0;
int blah = 0; //Blah is just a flag that im using that can be used to echo where i'v been and such
String firstname = "0";
String midinitial = "0";
String lastname = "0";
System.out.println("========================");
System.out.println("=Make a New Reservation=");
System.out.println("========================");
System.out.println();
System.out.println();
System.out.println();
System.out.println("What would you like?");
System.out.println();
System.out.println("1)First Class");
System.out.println("2)Coach");
System.out.println("");
classtype = console.readInt();
if (classtype == 1)
{
//First class is rows from 1 to 5
//so the start should be 0 and the end 5
y1 = 0;
y2 = 5;
}
if (classtype == 2)
{
//Coach is rows from 6 to 50
//so the start should be 5 and the end 50
y1 = 5;
y2 = 50;
}
System.out.println("");
System.out.println("");
System.out.println("What would you prefer?");
System.out.println("");
System.out.println("1) Window seat");
System.out.println("2) Aisle seat");
System.out.println("");
seatcolumn = console.readInt();
if (seatcolumn == 1)
{
//Window seat is columns 1 and 4
//so the varables should be 0 and 3
//for when i check the array for open seats
x1 = 0;
x2 = 3;
}
if (seatcolumn == 2)
{
//Window seat is columns 2 and 3
//so the varables should be 1 and 2
//for when i check the array for open seats
x1 = 1;
x2 = 2;
}
int seat_available = checkArray(x1, x2, y1, y2);
switch(seat_available)
{
case 0: //Seat is not available
{
System.out.println("Sorry, their isn't a seat available with the specifications you have given.");
System.out.println("Please try using other settings");
break;
}
case 1: //Seat is available
{
System.out.println("SEAT AVAILABLE");
System.out.println("");
System.out.println("We will now need some basic information:");
System.out.println("What is your first name?");
firstname = console.readToken();
System.out.println("What is your middle initial");
midinitial = console.readToken();
System.out.println("What is your last name?");
lastname = console.readToken();
blah = saveSeat(firstname, midinitial, lastname, xpos, ypos);
break;
}
}
return blah;
}//end of method
public int checkArray(int x1, int x2, int y1, int y2)
{
int seat_available = 0;
for (int y = y1; y < y2; y++)
{
//check the first row (x1) and see if there is a seat available
if(flight[x1][y].getLastname().equals("0"))
{
seat_available = 1;
xpos = x1;
ypos = y;
break;
}
//if an open seat hasnt been found, then check the 2nd row
if (seat_available == 0)
if(flight[x2][y].getLastname().equals("0"))
{
seat_available = 1;
xpos = x2;
ypos = y;
break;
}
}
return seat_available;
}
//Assign seatting
public int saveSeat(String firstname, String midinitial, String lastname, int x, int y)
{
int blah = 1;
flight[x][y] = new passenger(lastname, firstname, midinitial);
return blah;
}
public int ChangeReservation()
{
int blah = 0;
int x1 = -1;
int y1 = -1;
int ypos = -1;
String xpos = "nothing";
String firstname = "0";
String midinitial = "0";
String lastname = "0";
String column = "nothing";
System.out.println("=========================");
System.out.println("=Change your reservation=");
System.out.println("=========================");
System.out.println();
System.out.println("What is your first name?");
firstname = console.readToken();
System.out.println("What is your middle initial?");
midinitial = console.readToken();
System.out.println("What is your last name?");
lastname = console.readToken();
for (int x = 0; x < 4; x++)
for (int y = 0; y < 50; y++)
{
if (flight[x][y].getLastname().equals(lastname))
{
if (flight[x][y].getMidinitial().equals(midinitial))
{
if (flight[x][y].getFirstname().equals(firstname))
{
x1 = x;
y1 = y;
break;
}
}
}
}
//if the given name is not currently in the array, tell them that the name is invalid
if (x1 < 0 || y1 < 0)
{
System.out.println("Sorry, that name is not listed in our reservations");
}
//if the given name IS valid, then go on
if (x1 >= 0 && y1 >= 0)
{
//figure where they sit from varables x1 and y1
ypos = y1 + 1;
if (x1 == 0)
{
xpos = "A";
}
if (x1 == 1)
{
xpos = "B";
}
if (x1 == 2)
{
xpos = "C";
}
if (x1 == 3)
{
xpos = "D";
}
if (x1 == 0 || x1 == 3)
column = "Window";
else
column = "Aisle";
System.out.println("Your current seat is:");
System.out.println("(" + xpos +", " +ypos);
System.out.println("Next to the " +column);
System.out.println();
System.out.println("Are you sure you want to change?");
System.out.println("WARNING:");
System.out.println("If there is not a new available seat, you WILL lose your current seating!");
System.out.println("1) Yes");
System.out.println("2) No");
int change = console.readInt();
if (change == 1)
blah = NewReservation();
}
return blah;
}
public int Display()
{
int blah = 0;
System.out.println("|| A || B || C || D ||");
System.out.println("----------------------");
for (int y = 0; y < 50; y++)
{
System.out.print("|| ");
if (flight[0][y].getLastname().equals("0"))
System.out.print(" ");
else
System.out.print("X");
System.out.print(" || ");
if (flight[1][y].getLastname().equals("0"))
System.out.print(" ");
else
System.out.print("X");
System.out.print(" || ");
if (flight[2][y].getLastname().equals("0"))
System.out.print(" ");
else
System.out.print("X");
System.out.print(" || ");
if (flight[3][y].getLastname().equals("0"))
System.out.print(" ");
else
System.out.print("X");
System.out.println(" ||");
System.out.println("----------------------");
if (y % 10 == 0)
{
console.readInt();
System.out.println("Type '1' to continue");
}
}
return blah;
}
public int Seat()
{
String columns = "nothing";
String lastname = "0";
String firstname = "0";
String midinitial = "0";
int blah = 0;
int row = 0;
int column = 0;
System.out.println("Enter the column letter they are sitting in (A,B,C,D)");
columns = console.readToken();
System.out.println("Enter the row number you are sitting in");
row = console.readInt();
//change letters to numbers and such
if (columns == "A" || columns == "a")
column = 0;
if (columns == "B" || columns == "b")
column = 1;
if (columns == "C" || columns == "c")
column = 2;
if (columns == "D" || columns == "D")
column = 3;
row = row - 1;
//get the name at seat column, row
lastname = flight[column][row].getLastname();
firstname = flight[column][row].getFirstname();
midinitial = flight[column][row].getMidinitial();
System.out.print(lastname +", " +firstname +" " +midinitial);
System.out.println(" is sitting at (" +columns +", " +row +")");
System.out.println("");
System.out.println("type '1' to continue");
console.readInt();
return blah;
}
public int Person()
{
String firstname;
String midinitial;
String lastname;
String column = "0";
int blah = 0;
int x1 = -1;
int y1 = -1;
System.out.println("");
System.out.println("=======================");
System.out.println("=Where you are sitting=");
System.out.println("=======================");
System.out.println("");
System.out.println("What is your firstname?");
firstname = console.readToken();
System.out.println("What is your middle initial?");
midinitial = console.readToken();
System.out.println("What is your last name?");
lastname = console.readToken();
for (int x = 0; x < 4; x++)
for (int y = 0; y < 50; y++)
{
if (flight[x][y].getFirstname().equals(firstname))
if (flight[x][y].getMidinitial().equals(midinitial))
if (flight[x][y].getLastname().equals(lastname))
{
x1 = x;
y1 = y;
break;
}
}
if (x1 == 0)
column = "A";
if (x1 == 1)
column = "B";
if (x1 == 2)
column = "C";
if (x1 == 3)
column = "D";
y1 = y1 + 1;
System.out.println("");
System.out.print(firstname +" " +midinitial +" " +lastname);
System.out.print(" sits at ");
System.out.println("(" +column +", " +y1 +")");
return blah;
}
}//end of class
class MENU
{
ConsoleIO console = new ConsoleIO();
ARRAYSTUFF execute = new ARRAYSTUFF();
public void control()
{
execute.init();
int menuvar = 0;
int seat;
int seat_available;
while (menuvar < 1 || menuvar > 8)
{
System.out.println(Format.center("==============", 30));
System.out.println(Format.center("=====MENU=====", 30));
System.out.println(Format.center("==============", 30));
for (int c = 0; c < 5; c++)
System.out.println("");
System.out.println("1) Make a new Reservation");
System.out.println("2) Change an old Reservation");
System.out.println("3) Show a display of the plane");
System.out.println("4) Display who is in a specific seat");
System.out.println("5) Display what seat you are sitting in");
System.out.println("6) Save data to file");
System.out.println("7) Load data from file");
System.out.println("8) Quit");
for (int c = 0; c < 5; c++)
System.out.println("");
menuvar = console.readInt();
switch(menuvar)
{
case 1: //make a new reservation
{
int blah = execute.NewReservation();
menuvar = 0;
break;
}
case 2: //Change an old Reservation
{
int blah = execute.ChangeReservation();
menuvar = 0;
break;
}
case 3: //Show a display of the plane
{
int blah = execute.Display();
menuvar = 0;
break;
}
case 4: //Display who is in a specific seat
{
int blah = execute.Seat();
menuvar = 0;
break;
}
case 5: //Display what seat you are sitting in
{
int blah = execute.Person();
menuvar = 0;
break;
}
case 6: //save
{
execute.save();
menuvar = 0;
break;
}
case 7: //load
{
execute.retrieve();
menuvar = 0;
break;
}
}
}
}
}
i put it in the source box to.
sorry, i havnt commented it that much. i have a bad habbit of waiting to comment