/* * This is a rapid prototype of the Air Gourmet product written in Java */ // // This application was developed using Inprise JBuilder 2.0 // import java.io.*; import java.util.*; import java.text.*; //--------------------------------------------------------------------------------------------------------------------------------------------------- class CPassenger { private String passengerID; private String firstName; private char middleInit; private String lastName; private String suffix; private String address1; private String address2; private String city; private String state; private String postalCode; private String country; public String getPassengerID () { return passengerID; } public String getFirstName () { return firstName; } public char getMiddleInit () { return middleInit; } public String getLastName () { return lastName; } public String getSuffix () { return suffix; } public String getAddress1 () { return address1; } public String getAddress2 () { return address2; } public String getCity () { return city; } public String getState () { return state; } public String getPostalCode () { return postalCode; } public String getCountry () { return country; } public void setPassengerID (String s) { passengerID=s.toUpperCase (); } public void setFirstName (String f) { firstName=f.toUpperCase (); } public void setMiddleInit (char m) { middleInit = m; } public void setLastName (String l) { lastName=l.toUpperCase (); } public void setSuffix (String s) { suffix=s.toUpperCase (); } public void setAddress1 (String a1) { address1=a1.toUpperCase (); } public void setAddress2 (String a2) { address2=a2.toUpperCase (); } public void setCity (String c) { city=c.toUpperCase (); } public void setState (String s) { state=s.toUpperCase (); } public void setPostalCode (String p) { postalCode=p.toUpperCase (); } public void setCountry (String c) { country=c.toUpperCase (); } public void getDescription () // // getDescription retrieves passenger information // { String newPassengerID; AirGourmetUtilities.clearScreen (); if (AirGourmetData.passengerCount > AirGourmetData.NUM_PASSENGER_RECORDS) { System.out.println ("The maximum number of allowed passengers for this"); System.out.print ("prototype has been exceeded..."); System.out.println ("No new passengers are allowed.\n"); System.out.println (" Press to return to main menu..."); AirGourmetUtilities.pressEnter (); } else { System.out.print ("Please enter the following information"); System.out.println (" about the passenger.\n\n"); System.out.println ("Enter the PASSENGER ID assigned to this passenger"); System.out.print (" (9 numbers only--no spaces or dashes): "); newPassengerID=AirGourmetUtilities.readString (); AirGourmetData.fltRecs[AirGourmetData.fltRecCount].setPassengerID (newPassengerID); if (!alreadyExists (newPassengerID)) { AirGourmetData.passengers[AirGourmetData.passengerCurrent].setPassengerID (newPassengerID); System.out.print ("Enter the FIRST name of the passenger: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setFirstName (AirGourmetUtilities.readString ()); System.out.print ("Enter the MIDDLE INITIAL of the passenger: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setMiddleInit (AirGourmetUtilities.getChar ()); System.out.print ("Enter the LAST name of the passenger: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setLastName (AirGourmetUtilities.readString ()); System.out.print ("Enter the SUFFIX used by the passenger: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setSuffix (AirGourmetUtilities.readString ()); System.out.print ("Enter the ADDRESS (first line) of the passenger: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setAddress1 (AirGourmetUtilities.readString ()); System.out.print ("Enter the ADDRESS (second line) of the passenger: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setAddress2 (AirGourmetUtilities.readString ()); System.out.print ("Enter the CITY where the passenger lives: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setCity (AirGourmetUtilities.readString ()); System.out.print ("Enter the STATE where the passenger lives: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setState (AirGourmetUtilities.readString ()); System.out.print ("Enter the POSTAL CODE where the passenger lives: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setPostalCode (AirGourmetUtilities.readString ()); System.out.print ("Enter the COUNTRY where the passenger lives: "); AirGourmetData.passengers[AirGourmetData.passengerCurrent].setCountry (AirGourmetUtilities.readString ()); } } } // getDescription private boolean alreadyExists (String searchID) // // alreadyExists determines if the passenger ID of the current object already exists in the file // if the ID exists, then the user is asked if the values stored in the file // are to be used // { char ch; boolean found = false; int i; for (i = 0; i <= AirGourmetData.passengerCount; i++) { if (AirGourmetData.passengers[i].getPassengerID ().compareTo (searchID) == 0) { found = true; AirGourmetData.passengerCurrent = i; break; } } if (found) { System.out.println ("\n\n"); System.out.println ("The following passenger exists: \n\n"); System.out.println (AirGourmetData.passengers[i].getPassengerID () + " - " + AirGourmetData.passengers[i].getFirstName () + " " + AirGourmetData.passengers[i].getFirstName () + "\n"); System.out.println ("Do you want to use this name and address to make a "); System.out.print ("reservation for this passenger (Y/N)? "); ch=AirGourmetUtilities.getChar (); System.out.println ("\n"); found = false; if (Character.toUpperCase (ch) == 'Y') found = true; } else { AirGourmetData.passengerCount++; AirGourmetData.passengerCurrent = AirGourmetData.passengerCount; } return found; } // alreadyExists } // class CPassenger //--------------------------------------------------------------------------------------------------------------------------------------------------- class CFlightRecord { public static String mealTypeValues[] = {"Child ", "Diabetic ", "Halaal ", "Kosher ", "Lactose Free ", "Low Calorie ", "Low Cholesterol", "Low Fat ", "Low Protein ", "Low Sodium ", "Sea Food ", "Vegan ", "Vegetarian "}; private String passengerID; private String reservationID; private String flightNum; private Date flightDate; private String seatNum; private char mealType; private short perceivedQuality; private boolean checkedIn; private boolean mealLoaded; public String getPassengerID () { return passengerID; } public String getReservationID () { return reservationID; } public String getFlightNum () { return flightNum; } public Date getFlightDate () { return flightDate; } public String getSeatNum () { return seatNum; } public char getMealType () { return mealType; } public short getPerceivedQuality () { return perceivedQuality; } public boolean getCheckedIn () { return checkedIn; } public boolean getMealLoaded () { return mealLoaded; } public void setPassengerID (String s) { passengerID = s.toUpperCase (); } public void setReservationID (String r) { reservationID = r.toUpperCase (); } public void setFlightNum (String f) { flightNum = f.toUpperCase (); } public void setFlightDate (Date d) { flightDate = d; } public void setSeatNum (String s) { seatNum = s.toUpperCase (); } public void setMealType (char m) { mealType = m; } public void setPerceivedQuality (short p) { perceivedQuality = p; } public void setCheckedIn (boolean c) { checkedIn = c; } public void setMealLoaded (boolean m) { mealLoaded = m; } public void getReservation () // // getReservation retrieves flight reservation information // { boolean dateOK = false; CPassenger aPassenger = new CPassenger (); String flightStrDate; SimpleDateFormat flightDateFormat = new SimpleDateFormat ("MMM/dd/yyyy"); AirGourmetUtilities.clearScreen (); if (AirGourmetData.fltRecCount > AirGourmetData.NUM_FLIGHT_RECORDS) { System.out.println ("The maximum number of reservations for this"); System.out.println ("prototype has been exceeded..." + "No new reservations are allowed.\n"); System.out.println (" Press to return to main menu..."); AirGourmetUtilities.pressEnter (); } else { AirGourmetData.fltRecCount++; System.out.println ("Please enter the following information about the reservation.\n\n"); System.out.print ("Enter the RESERVATION ID: "); AirGourmetData.fltRecs[AirGourmetData.fltRecCount].setReservationID (AirGourmetUtilities.readString ()); System.out.print ("Enter the FLIGHT NUMBER: "); AirGourmetData.fltRecs[AirGourmetData.fltRecCount].setFlightNum (AirGourmetUtilities.readString ()); while (!dateOK) { System.out.print ("Enter the DATE of the flight: "); flightStrDate = AirGourmetUtilities.readString (); dateOK = true; try { AirGourmetData.fltRecs[AirGourmetData.fltRecCount].setFlightDate (flightDateFormat.parse (flightStrDate)); } catch (ParseException pe) { System.out.println ("\n\tYou entered the date incorrectly.\n"); System.out.println ("\tPlease use the format mmm/dd/yyyy.\n\n"); dateOK = false; } } System.out.print ("Enter the SEAT NUMBER assigned to this passenger: "); AirGourmetData.fltRecs[AirGourmetData.fltRecCount].setSeatNum (AirGourmetUtilities.readString ()); System.out.println ("\n\nList of available special meals:\n\n"); System.out.println (" A - Child B - Diabetic C - Halaal\n"); System.out.println (" D - Kosher E - Lactose Free F - Low Cal\n"); System.out.println (" G - Low Cholesterol H - Low Fat I - Low Protein\n"); System.out.println (" J - Low Sodium K - Sea Food L - Vegan\n"); System.out.println (" M - Vegetarian\n\n"); System.out.print ("Enter the SPECIAL MEAL for this reservation: "); AirGourmetData.fltRecs[AirGourmetData.fltRecCount].setMealType (Character.toUpperCase (AirGourmetUtilities.getChar ())); } aPassenger.getDescription (); } // getReservation public void checkInPassenger () // // checkInPassenger sets checkedIn to true for a specific reservation // { int i; boolean found = false; AirGourmetUtilities.clearScreen (); System.out.print ("Enter the RESERVATION ID: "); reservationID=AirGourmetUtilities.readString (); for (i = 0; i <= AirGourmetData.fltRecCount; i++) if (AirGourmetData.fltRecs[i].getReservationID ().compareTo (reservationID) == 0) { found = true; AirGourmetData.fltRecs[i].setCheckedIn (true); System.out.println ("\n\n\tThe passenger has been checked in.\n"); System.out.println ("\tPlease check their identification.\n"); System.out.println ("\n\nPress to return to main menu..."); AirGourmetUtilities.pressEnter (); break; } if (!found) { System.out.println ("\n\n\tThere is no reservation with this ID..."); System.out.println ("\n\nPress to return to main menu..."); AirGourmetUtilities.pressEnter (); } } // checkInPassenger public void scanSpecialMeals () // // scanSpecialMeals queries the user whether the meal was loaded and then updates the file. // It does this for all of the reservations on a specific flight (flight number + flight date), // { char ch; boolean found = false; boolean dateOK = false; String flightStrDate; SimpleDateFormat flightDateFormat = new SimpleDateFormat ("MMM/dd/yyyy"); int i; AirGourmetUtilities.clearScreen (); while (!dateOK) { System.out.print ("Enter the DATE of the flight: "); flightStrDate = AirGourmetUtilities.readString (); dateOK = true; try { flightDate = flightDateFormat.parse (flightStrDate); } catch (ParseException pe) { System.out.println ("\n\tYou entered the date incorrectly.\n"); System.out.println ("\tPlease use the format mmm/dd/yyyy.\n\n"); dateOK = false; } } System.out.print ("Enter the FLIGHT NUMBER: "); flightNum = AirGourmetUtilities.readString (); AirGourmetUtilities.clearScreen (); for (i = 0; i <= AirGourmetData.fltRecCount; i++) if ((AirGourmetData.fltRecs[i].getFlightDate ().equals (flightDate)) && (AirGourmetData.fltRecs[i].getFlightNum ().compareTo (flightNum) == 0)) { found = true; System.out.println ("\n\nPASSENGER: " + AirGourmetData.fltRecs[i].getPassengerID ()); System.out.println (" SEAT: " + AirGourmetData.fltRecs[i].getSeatNum ()); System.out.println (" MEAL TYPE: " + mealTypeValues[AirGourmetData.fltRecs[i].getMealType () - 'A']); System.out.print ("\n\nWas the meal for this passenger loaded (Y/N) ? "); ch = AirGourmetUtilities.getChar (); if (Character.toUpperCase (ch) == 'Y') AirGourmetData.fltRecs[i].setMealLoaded (true); else AirGourmetData.fltRecs[i].setMealLoaded (false); } if (!found) System.out.print ("\n\n\tThere are no passengers on this flight..."); System.out.println ("\n\nPress to return to main menu..."); AirGourmetUtilities.pressEnter (); } // scanSpecialMeals public void scanPostcard () // // scanPostcard sets perceivedQuality for a specific reservation to a value entered // by the user and inserts the change // { boolean found = false; int i; AirGourmetUtilities.clearScreen (); System.out.print ("Enter the RESERVATION ID: "); reservationID=AirGourmetUtilities.readString (); for (i = 0; i <= AirGourmetData.fltRecCount; i++) if (AirGourmetData.fltRecs[i].getReservationID ().compareTo (reservationID) == 0) { found = true; String tempString; System.out.print ("Enter perceived meal quality (1 thru 5): "); tempString = AirGourmetUtilities.readString (); AirGourmetData.fltRecs[i].setPerceivedQuality ( (short) Integer.parseInt (tempString)); System.out.println ("\n\n\tThe passenger record has been updated.\n"); break; } if (!found) System.out.println ("\n\n\tThere is no reservation with this ID..."); System.out.println ("\n\nPress to return to main menu..."); AirGourmetUtilities.pressEnter (); } // scanPostcard } // class CFlightRecord //--------------------------------------------------------------------------------------------------------------------------------------------------- class AirGourmetReports { public static void lowSodiumReport () { boolean dateOK = false; String fromStrDate, toStrDate; int numRecs = 0; int i; Date fromDate = new Date (); Date toDate = new Date (); SimpleDateFormat flightDateFormat = new SimpleDateFormat ("MMM/dd/yyyy"); Calendar toCalendar = new GregorianCalendar (); Calendar fromCalendar = new GregorianCalendar (); AirGourmetUtilities.clearScreen (); while (!dateOK) { System.out.print ("Enter the start date for the report: "); fromStrDate = AirGourmetUtilities.readString (); dateOK = true; try { fromDate = flightDateFormat.parse (fromStrDate); fromCalendar.setTime (fromDate); } catch (ParseException pe) { System.out.println ("\n\tYou entered the date incorrectly.\n"); System.out.println ("\tPlease use the format mmm/dd/yyyy.\n\n"); dateOK = false; } } dateOK = false; while (!dateOK) { System.out.print ("Enter the end date for the report: "); toStrDate = AirGourmetUtilities.readString (); dateOK = true; try { toDate = flightDateFormat.parse (toStrDate); toCalendar.setTime (toDate); } catch (ParseException pe) { System.out.println ("\n\tYou entered the date incorrectly.\n"); System.out.println ("\tPlease use the format mmm/dd/yyyy.\n\n"); dateOK = false; } } AirGourmetUtilities.clearScreen (); if (AirGourmetData.fltRecCount >= 0) { for (i = 0; i <= AirGourmetData.fltRecCount; i++) if ((AirGourmetData.fltRecs[i].getMealLoaded () == true) && (AirGourmetData.fltRecs[i].getMealType () == 'J') && ((AirGourmetData.fltRecs[i].getFlightDate ().after (fromDate)) || (AirGourmetData.fltRecs[i].getFlightDate ().equals (fromDate))) && ((AirGourmetData.fltRecs[i].getFlightDate ().before (toDate)) || (AirGourmetData.fltRecs[i].getFlightDate ().equals (toDate))) ) { if (((numRecs % 3) == 0) && (numRecs != 0)) { System.out.println ("\n\n Press to view the next screen..."); AirGourmetUtilities.pressEnter (); } if ((numRecs % 3) == 0) { AirGourmetUtilities.clearScreen (); System.out.println ("\n\n\t\t Air Gourmet\n"); System.out.println ("\t\t\t Low Sodium Report\n"); } System.out.println ("-----------------------------------------------------------------------------"); System.out.println ("FLIGHT NUMBER: " + AirGourmetData.fltRecs[i].getFlightNum ()); System.out.println ("FLIGHT DATE: " + flightDateFormat.format(AirGourmetData.fltRecs[i].getFlightDate ())); System.out.println ("PERCEIVED QUALITY: " + AirGourmetData.fltRecs[i].getPerceivedQuality ()); numRecs++; } } if (numRecs == 0) System.out.println ("\n\n\tThere were no records to print...\n\n"); System.out.println ("\n\nPress to return to main menu..."); AirGourmetUtilities.pressEnter (); } // lowSodiumReport public static void onBoardReport () { boolean dateOK = false; String flightNum; String flightStrDate; int numRecs = 0; int i; Date fromDate = new Date (); SimpleDateFormat flightDateFormat = new SimpleDateFormat ("MMM/dd/yyyy"); Calendar fromCalendar = new GregorianCalendar (); AirGourmetUtilities.clearScreen (); while (!dateOK) { System.out.print ("Enter the DATE of the flight: "); flightStrDate = AirGourmetUtilities.readString (); dateOK = true; try { fromDate = flightDateFormat.parse (flightStrDate); } catch (ParseException pe) { System.out.println ("\n\tYou entered the date incorrectly.\n"); System.out.println ("\tPlease use the format mmm/dd/yyyy.\n\n"); dateOK = false; } } System.out.print ("Enter the FLIGHT NUMBER: "); flightNum = AirGourmetUtilities.readString (); AirGourmetUtilities.clearScreen (); for (i = 0; i <= AirGourmetData.fltRecCount; i++) if ((AirGourmetData.fltRecs[i].getFlightDate ().equals (fromDate)) && (AirGourmetData.fltRecs[i].getFlightNum ().compareTo (flightNum) == 0)) { if (((numRecs % 10) == 0) && (numRecs != 0)) { System.out.println ("\n\n Press to view the next screen..."); AirGourmetUtilities.pressEnter (); } if ((numRecs % 10) == 0) { AirGourmetUtilities.clearScreen (); System.out.println ("\n\n\t\t Air Gourmet\n"); System.out.println ("\t\t\t On Board Meals List\n"); } System.out.println ("-----------------------------------------------------------------------------"); System.out.println ("PASSENGER: " + AirGourmetData.fltRecs[i].getPassengerID () + " SEAT: " + AirGourmetData.fltRecs[i].getSeatNum () + " MEAL TYPE: " + CFlightRecord.mealTypeValues[AirGourmetData.fltRecs[i].getMealType () - 'A'] + " |__|"); numRecs++; } if (numRecs == 0) System.out.println ("\n\n\tThere were no records to print...\n\n"); System.out.println ("\n\nPress to return to main menu..."); AirGourmetUtilities.pressEnter (); } // onBoardReport } // AirGourmetReports class AirGourmetUtilities { public static char getChar () // // getChar returns the first character entered from the keyboard // { char ch = '\n'; try { Reader in = new InputStreamReader (System.in); ch= (char) in.read (); } catch (Exception e) { System.out.println ("Error: " + e.toString ()); } return ch; } // getChar public static String readString () // // readString returns a string entered from the keyboard // { StringBuffer tempBuffer = new StringBuffer (); StringBuffer sb = new StringBuffer (); String tempString; char c; int i; try { while ((c = (char) System.in.read ( )) != '\n') { tempBuffer.append (c); } } catch (Exception e) { System.out.println ("Exception: " + e.getMessage ( ) + "has occurred"); } tempString = tempBuffer.toString (); for (i=0; i key // { char ch = '\n'; Reader in = new InputStreamReader (System.in); try { while ((ch= (char) in.read ()) != '\n'); } catch (Exception e) { System.out.println ("Error: " + e.toString ()); } } // pressEnter private static void displayReportMenu () // // displayReportMenu displays the menu containing all the reporting options // available to the user // { boolean done; char choice; done = false; while (!done) { clearScreen (); System.out.println (" Air Gourmet - REPORT MENU\n\n"); System.out.println (" 1. *24 Hour Caterer List\n"); System.out.println (" 2. On Board Meals List\n"); System.out.println (" 3. *Report on Percentages\n"); System.out.println (" 4. *Report on Meals not Loaded\n"); System.out.println (" 5. *Report on Poor Quality\n"); System.out.println (" 6. Report on Low Sodium\n"); System.out.println (" 7. Return to Main Menu\n\n"); System.out.println (" (* denotes not implemented)\n\n"); System.out.print (" Enter your choice and press : "); choice=getChar (); switch (choice) { case '1': clearScreen (); System.out.println (" 24 HOUR CATERER LIST\n\n"); System.out.println (" This report is not implemented in the prototype\n\n\n"); System.out.println (" Press to return to the menu..."); pressEnter (); break; case '2': AirGourmetReports.onBoardReport (); break; case '3': clearScreen (); System.out.println (" REPORT ON PERCENTAGES\n\n"); System.out.println (" This report is not implemented in the prototype\n\n\n"); System.out.println (" Press to return to the menu..."); pressEnter (); break; case '4': clearScreen (); System.out.println (" REPORT ON MEALS NOT LOADED\n\n"); System.out.println (" This report is not implemented in the prototype\n\n\n"); System.out.println (" Press to return to the menu..."); pressEnter (); break; case '5': clearScreen (); System.out.println (" REPORT ON POOR QUALITY\n\n"); System.out.println (" This report is not implemented in the prototype\n\n\n"); System.out.println (" Press to return to the menu..."); pressEnter (); break; case '6': AirGourmetReports.lowSodiumReport (); break; case '7': done = true; break; default: System.out.println ("\n\nChoice is out of range\n\n"); System.out.println (" Press to return to menu..."); pressEnter (); break; } // switch (choice) } // while (!done) } // displayReportMenu public static void displayMainMenu () // // displayMainMenu displays the main menu containing all the options available to the user // { boolean done; char choice; CFlightRecord flightRecord = new CFlightRecord (); CPassenger passenger = new CPassenger (); done = false; while (!done) { clearScreen (); System.out.println (" Air Gourmet - MAIN MENU\n\n"); System.out.println (" 1. Enter a Reservation\n"); System.out.println (" 2. Check-in a Passenger\n"); System.out.println (" 3. Scan the Special Meals List\n"); System.out.println (" 4. Scan a Returned Postcard\n"); System.out.println (" 5. Produce a Report\n"); System.out.println (" 6. Quit\n\n"); System.out.print (" Enter your choice and press : "); choice =getChar (); switch (choice) { case '1': flightRecord.getReservation (); break; case '2': flightRecord.checkInPassenger (); break; case '3': flightRecord.scanSpecialMeals (); break; case '4': flightRecord.scanPostcard (); break; case '5': displayReportMenu (); break; case '6': System.out.println ("\n\nThank you for using Air Gourmet!!\n\n"); System.out.println (" Press to exit..."); pressEnter (); done = true; break; default: System.out.println ("\n\nChoice is out of range\n\n"); System.out.println (" Press to return to menu..."); pressEnter (); break; } // switch (choice) } // while (!done) } // displayMainMenu } // class AirGourmetUtilities public class AirGourmetData { public static final int NUM_FLIGHT_RECORDS = 20; public static final int NUM_PASSENGER_RECORDS = 10; // // Because this is a rapid prototype, an array of records has been used to // keep track of the number of flight records and passenger records // public static int fltRecCount; public static int passengerCount; public static int passengerCurrent; public static CFlightRecord fltRecs[] = new CFlightRecord[NUM_FLIGHT_RECORDS]; public static CPassenger passengers[]= new CPassenger [NUM_PASSENGER_RECORDS]; public static void initialize () { int i; fltRecCount = -1; passengerCount = -1; for (i = 0; i < NUM_FLIGHT_RECORDS; i++) { fltRecs[i] = new CFlightRecord (); fltRecs[i].setPerceivedQuality ( (short) -1); fltRecs[i].setCheckedIn (false); fltRecs[i].setMealLoaded (false); } for (i = 0; i < NUM_PASSENGER_RECORDS; i++) passengers[i] = new CPassenger (); } } // class AirGourmetData public class AirGourmetProto { public static void main (String[] args) { AirGourmetData.initialize (); AirGourmetUtilities.displayMainMenu (); } } // class AirGourmetProto