⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 airgourmetproto.java

📁 AirGourmet:空中美食管理系统。国外一个学习软件工程的经典例子。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

/*
 * 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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER> 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 ();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -