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

📄 airgourmetproto.java

📁 AirGourmet:空中美食管理系统。国外一个学习软件工程的经典例子。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER> 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<tempString.length () - 1; i++)
			sb.append (tempString.charAt (i));

		return sb.toString ();
	}

	public static void clearScreen ()
	//
	// clearScreen clears the screen
	//
	{
		int						i;

		for (i = 0; i < 26; i++)
			System.out.println ("");

	} // clearScreen

	public static void pressEnter ()
	//
	// pressEnter waits until the user presses the <ENTER> 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 <ENTER>: ");

			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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER> 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 <ENTER>: ");

			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 <ENTER> to exit...");
					pressEnter ();
					done = true;
					break;

				default:
					System.out.println ("\n\nChoice is out of range\n\n");
					System.out.println ("       Press <ENTER> 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

⌨️ 快捷键说明

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