import java.util.Scanner;
import java.text.DecimalFormat;
public class A_G_RestaurantOrderv6
{
public static void main(String[] args)
{
//Display and introduce the program to the user via title.
System.out.println("\t\t\t\t\t*****************************");
System.out.println("\t\t\t\t\t* Welcome to Cafč Java! *");
System.out.println("\t\t\t\t\t*****************************");
//Create Scanner object and DecimalFormat object.
Scanner keyinput = new Scanner(System.in);
/*Creating a DecimalFormat object for each sub menu's prices. While this could be done with
*one generalized DecimalFormat object, I prefer to make one for each that way it can be easier to
*identify and it just fits my coding style.
*/
DecimalFormat currencyFormat = new DecimalFormat ("$0.00");
//Provide instructions to the user and ask them to enter the number of people in their group.
System.out.print("\nHow many people are in your group? ");
int peopleInGroup = keyinput.nextInt();
System.out.println("Each person must order an item from the following menu categories: appetizers, entrčes, desserts and beverages.");
//Create an accumulator variable that will add the price of each diner's selection.
double totalBill = 0.0;
//Set up a main for loop that will run code based on the number of people in a group.
for(int i = 1; i <= peopleInGroup; i++)
{
System.out.println("\nDiner # " + i + ", what will your order consist of?");
System.out.println("*******************************************");
//Create and instantaniate eight arrays: four to hold String variables for menu items, and four double arrays to hold prices of those menu items.
String[] appetizerNamesArray = new String[] {null, "No Selection", "Deep Fried Calamari", "Soup du Jour", "Garden Salad", "Garlic Bread"};
String[] entreeNamesArray = new String[] {null, "No Selection", "Rib-Steak", "Fettuccini Alfredo", "Pan-Fried Sole", "Mediterranean Platter", "Vegetarian Lasagna"};
String[] dessertNamesArray = new String[] {null, "No Selection", "Ice Cream Sundae", "Cheesecake", "Chocolate Truffle Cake", "Raspberry Mousse"};
String[] beverageNamesArray = new String[] {null, "No Selection", "Water", "Juice", "Pop", "Milk", "Coffee", "Tea"};
double[] appetizerPriceArray = new double[] {0.00, 0.00, 7.50, 4.99, 3.99, 4.50};
double[] entreePriceArray = new double[] {0.00, 0.00, 15.95, 11.25, 17.95, 13.50, 9.00};
double[] dessertPriceArray = new double[] {0.00, 0.00, 2.95, 5.00, 6.00, 4.50};
double[] beveragePriceArray = new double[] {0.00, 0.00, 0.00, 2.00, 2.00, 2.00, 1.75, 1.75};
//Display appetizer menu for the diner and take the diner's selection off the menu.
System.out.println("\n\t*****************************");
System.out.println("\t* Appetizer Sub-Menu *");
System.out.println("\t*****************************");
//Print out the element that contains the menu item and its price, formatted to the currencyFormat.
System.out.println("\t1. ** " + appetizerNamesArray[1] + " ** " + currencyFormat.format(appetizerPriceArray[1]));
System.out.println("\t2. " + appetizerNamesArray[2] + " " + currencyFormat.format(appetizerPriceArray[2]));
System.out.println("\t3. " + appetizerNamesArray[3] + " " + currencyFormat.format(appetizerPriceArray[3]));
System.out.println("\t4. " + appetizerNamesArray[4] + " " + currencyFormat.format(appetizerPriceArray[4]));
System.out.println("\t5. " + appetizerNamesArray[5] + " " + currencyFormat.format(appetizerPriceArray[5]));
//Create a do-while loop that will validate the data prior to entering it into the accumulator for the totalBill. It will keep the user
//inside of the loop until a valid selection is inputted.
int appetizerSelection;
boolean badDataFlag = true;
System.out.print("\nPlease select ONE item from the Appetizer menu #: ");
do
{
appetizerSelection = keyinput.nextInt();
if(appetizerSelection < 1 || appetizerSelection > 5)
{
System.out.print("That is not a valid selection, please choose ONE item from the Entrče menu #: ");
}
else
{
badDataFlag = false;
}
}while (badDataFlag == true);
totalBill += appetizerPriceArray[appetizerSelection]; //Add the selected item's price, from the menu, to the totalBill.
//Display entrče menu for the diner and take the diner's selection from the menu.
System.out.println("\n\t*****************************");
System.out.println("\t* Entrče Sub-Menu *");
System.out.println("\t*****************************");
System.out.println("\t1. ** " + entreeNamesArray[1] + " ** " + currencyFormat.format(entreePriceArray[1]));
System.out.println("\t2. " + entreeNamesArray[2] + " " + currencyFormat.format(entreePriceArray[2]));
System.out.println("\t3. " + entreeNamesArray[3] + " " + currencyFormat.format(entreePriceArray[3]));
System.out.println("\t4. " + entreeNamesArray[4] + " " + currencyFormat.format(entreePriceArray[4]));
System.out.println("\t5. " + entreeNamesArray[5] + " " + currencyFormat.format(entreePriceArray[5]));
System.out.println("\t6. " + entreeNamesArray[6] + " " + currencyFormat.format(entreePriceArray[6]));
//Create a do-while loop that will validate the data prior to entering it into the accumulator for the totalBill. It will keep the user
//inside of the loop until a valid selection is inputted.
int entreeSelection;
System.out.print("\nPlease select ONE item from the Entrče menu #: ");
do
{
badDataFlag = true;
entreeSelection = keyinput.nextInt();
if(entreeSelection < 1 || entreeSelection > 6)
{
System.out.print("That is not a valid selection, please choose ONE item from the Entrče menu #: ");
}
else
{
badDataFlag = false;
}
}while (badDataFlag == true);
totalBill += entreePriceArray[entreeSelection]; //Add the selected item's price, from the menu, to the totalBill.
//Display dessert menu for the diner and take the diner's selection from the menu.
System.out.println("\n\t*****************************");
System.out.println("\t* Dessert Sub-Menu *");
System.out.println("\t*****************************");
System.out.println("\t1. ** " + dessertNamesArray[1] + " ** " + currencyFormat.format(dessertPriceArray[1]));
System.out.println("\t2. " + dessertNamesArray[2] + " " + currencyFormat.format(dessertPriceArray[2]));
System.out.println("\t3. " + dessertNamesArray[3] + " " + currencyFormat.format(dessertPriceArray[3]));
System.out.println("\t4. " + dessertNamesArray[4] + " " + currencyFormat.format(dessertPriceArray[4]));
System.out.println("\t5. " + dessertNamesArray[5] + " " + currencyFormat.format(dessertPriceArray[5]));
//Create a do-while loop that will validate the data prior to entering it into the accumulator for the totalBill. It will keep the user
//inside of the loop until a valid selection is inputted.
int dessertSelection;
System.out.print("\nPlease select ONE item from the Dessert menu #: ");
do
{
badDataFlag = true;
dessertSelection = keyinput.nextInt();
if(dessertSelection < 1 || dessertSelection > 5)
{
System.out.print("That is not a valid selection, please choose ONE item from the Entrče menu #: ");
}
else
{
badDataFlag = false;
}
}while (badDataFlag == true);
totalBill += dessertPriceArray[dessertSelection]; //Add the selected item's price, from the menu, to the totalBill.
//Display dessert menu for the diner and take the diner's selection from the menu.
System.out.println("\n\t*****************************");
System.out.println("\t* Beverage Sub-Menu *");
System.out.println("\t*****************************");
System.out.println("\t1. ** " + beverageNamesArray[1] + " ** " + currencyFormat.format(beveragePriceArray[1]));
System.out.println("\t2. " + beverageNamesArray[2] + " " + currencyFormat.format(beveragePriceArray[2]));
System.out.println("\t3. " + beverageNamesArray[3] + " " + currencyFormat.format(beveragePriceArray[3]));
System.out.println("\t4. " + beverageNamesArray[4] + " " + currencyFormat.format(beveragePriceArray[4]));
System.out.println("\t5. " + beverageNamesArray[5] + " " + currencyFormat.format(beveragePriceArray[5]));
System.out.println("\t6. " + beverageNamesArray[6] + " " + currencyFormat.format(beveragePriceArray[6]));
System.out.println("\t7. " + beverageNamesArray[7] + " " + currencyFormat.format(beveragePriceArray[7]));
//Create a do-while loop that will validate the data prior to entering it into the accumulator for the totalBill. It will keep the user
//inside of the loop until a valid selection is inputted.
int beverageSelection;
System.out.print("\nPlease select ONE item from the Beverage menu #: ");
do
{
badDataFlag = true;
beverageSelection = keyinput.nextInt();
if(beverageSelection < 1 || beverageSelection > 7)
{
System.out.print("That is not a valid selection, please choose ONE item from the Entrče menu #: ");
}
else
{
badDataFlag = false;
}
}while (badDataFlag == true);
totalBill += beveragePriceArray[beverageSelection]; //Add the selected item's price, from the menu, to the totalBill.
//Display diner's order.
if(appetizerSelection == 1 && entreeSelection == 1 && dessertSelection == 1 && beverageSelection == 1)
{
System.out.println();
}
else
{
System.out.println("\nThank you. Your order will consist of:");
}//end thank you message if
if (appetizerSelection != 1)
{
System.out.println("\t" + appetizerNamesArray[appetizerSelection]);
}//end appetizer if
if (entreeSelection != 1)
{
System.out.println("\t" + entreeNamesArray[entreeSelection]);
}//end entree if
if (dessertSelection != 1)
{
System.out.println("\t" + dessertNamesArray[dessertSelection]);
}//end dessert if
if (beverageSelection != 1)
{
System.out.println("\t" + beverageNamesArray[beverageSelection]);
}//end beverage if
}//end main for
//Output the total bill for all the diners.
System.out.println("-------------------------------------------------");
System.out.println("Order completed. Your total bill comes to " + currencyFormat.format(totalBill));
System.out.println("-------------------------------------------------");
}//end main
}//end class