Assignment 9

























import javax.swing.JOptionPane;
public class restaurant {
public static void main(String[] args)
{
String
//names to be input
nameA, nameB,
//numbers to be input
number1A, number2A, number3A, number4A, number1B, number2B, number3B, number4B,
appA, souA, salA, entA, appB, souB, salB, entB,
//what item they want to choose...
appYesA, soupYesA, saladYesA, entreeYesA, appYesB, soupYesB, saladYesB, entreeYesB;
//If they want "whatever" or not
double appetizerA, soupA, saladA, entreeA, appetizerB, soupB, saladB, entreeB,
//price of "whatever" they want
appPrA, soupPrA, saladPrA, entreePrA, appPrB, soupPrB, saladPrB, entreePrB,
//totals
totalA,
totalB;
//greeting
JOptionPane.showMessageDialog(
null, "Welcome to the Century Hotel's Restaurant!", "Welcome!",
JOptionPane.PLAIN_MESSAGE);
//getting imput from the user
nameA = JOptionPane.showInputDialog("What is the name of the first person to order?");
nameB = JOptionPane.showInputDialog("What is the name of the second person to order?");
//imput from "nameA"
number1A = JOptionPane.showInputDialog(nameA + ", do you want an appetizer? (1=yes,0=no)");
number2A = JOptionPane.showInputDialog(nameA + ", do you want soup? (1=yes,0=no)");
number3A = JOptionPane.showInputDialog(nameA + ", do you want salad? (1=yes,0=no)");
number4A = JOptionPane.showInputDialog(nameA + ", do you want an entree? (1=yes,0=no)");
//changing the imput from characters to integers.
appetizerA = Double.parseDouble(number1A);
soupA = Double.parseDouble(number2A);
saladA = Double.parseDouble(number3A);
entreeA = Double.parseDouble(number4A);
//if "nameA" wants an appetizer
if (appetizerA == 1)
{
appYesA = JOptionPane.showInputDialog(nameA + ", What appetizer do you want?");
appA = JOptionPane.showInputDialog(nameA + ", What is the price of " + appYesA + " (in dollars)?");
}
else
{
JOptionPane.showMessageDialog(
null, nameA + ", you have chosen not to order an appetizer", "Note:",
JOptionPane.PLAIN_MESSAGE);
appYesA = "No Appetizer Selected";
appA = "0";
}
//if "nameA" wants soup
if (soupA == 1)
{
soupYesA = JOptionPane.showInputDialog(nameA + ", What kind of soup do you want?");
souA = JOptionPane.showInputDialog(nameA + ", What is the price of " + soupYesA + " (in dollars)?");
}
else
{
JOptionPane.showMessageDialog(
null, nameA + ", you have chosen not to order soup", "Note:",
JOptionPane.PLAIN_MESSAGE);
soupYesA = "No Soup Selected";
souA = "0";
}
//if "nameA" wants salad
if (saladA == 1)
{
saladYesA = JOptionPane.showInputDialog(nameA + ", What type of salad do you want?");
salA = JOptionPane.showInputDialog(nameA + ", What is the price of " + saladYesA + " (in dollars?)");
}
else
{
JOptionPane.showMessageDialog(
null, nameA + ", you have chosen not to order salad", "Note:",
JOptionPane.PLAIN_MESSAGE);
saladYesA = "No Salad Selected";
salA = "0";
}
//if "nameA" wants an entree
if (entreeA == 1)
{
entreeYesA = JOptionPane.showInputDialog(nameA + ", What entree do you want?");
entA = JOptionPane.showInputDialog(nameA + ", What is the price of " + entreeYesA + " (in dollars?)");
}
else
{
JOptionPane.showMessageDialog(
null, nameA + ", you have chosen not to order an entree", "Note:",
JOptionPane.PLAIN_MESSAGE);
entreeYesA = "No Entree Selected";
entA = "0";
}
//imput from "nameB"
number1B = JOptionPane.showInputDialog(nameB + ", do you want an appetizer? (1=yes,0=no)");
number2B = JOptionPane.showInputDialog(nameB + ", do you want soup? (1=yes,0=no)");
number3B = JOptionPane.showInputDialog(nameB + ", do you want salad? (1=yes,0=no)");
number4B = JOptionPane.showInputDialog(nameB + ", do you want an entree? (1=yes,0=no)");
//changing the imput from characters to integers.
appetizerB = Double.parseDouble(number1B);
soupB = Double.parseDouble(number2B);
saladB = Double.parseDouble(number3B);
entreeB = Double.parseDouble(number4B);
//if "nameB" wants an appetizer
if (appetizerB == 1)
{
appYesB = JOptionPane.showInputDialog(nameB + ", What appetizer do you want?");
appB = JOptionPane.showInputDialog(nameB + ", What is the price of " + appYesB + " (in dollars)?");
}
else
{
JOptionPane.showMessageDialog(
null, nameB + ", you have chosen not to order an appetizer", "Note:",
JOptionPane.PLAIN_MESSAGE);
appYesB = "No Appetizer Selected";
appB = "0";
}
//if "nameB" wants soup
if (soupB == 1)
{
soupYesB = JOptionPane.showInputDialog(nameB + ", What kind of soup do you want?");
souB = JOptionPane.showInputDialog(nameB + ", What is the price of " + soupYesB + " (in dollars)?");
}
else
{
JOptionPane.showMessageDialog(
null, nameB + ", you have chosen not to order soup", "Note:",
JOptionPane.PLAIN_MESSAGE);
soupYesB = "No Soup Selected";
souB = "0";
}
//if "nameB" wants salad
if (saladB == 1)
{
saladYesB = JOptionPane.showInputDialog(nameB + ", What type of salad do you want?");
salB = JOptionPane.showInputDialog(nameB + ", What is the price of " + saladYesB + " (in dollars?)");
}
else
{
JOptionPane.showMessageDialog(
null, nameB + ", you have chosen not to order salad", "Note:",
JOptionPane.PLAIN_MESSAGE);
saladYesB = "No Salad Selected";
salB = "0";
}
//if "nameB" wants an entree
if (entreeB == 1)
{
entreeYesB = JOptionPane.showInputDialog(nameB + ", What entree do you want?");
entB = JOptionPane.showInputDialog(nameA + ", What is the price of " + entreeYesB + " (in dollars?)");
}
else
{
JOptionPane.showMessageDialog(
null, nameB + ", you have chosen not to order an entree", "Note:",
JOptionPane.PLAIN_MESSAGE);
entreeYesB = "No Entree Selected";
entB = "0";
}
//change values to double
appPrA = Double.parseDouble(appA);
soupPrA = Double.parseDouble(souA);
saladPrA = Double.parseDouble(salA);
entreePrA = Double.parseDouble(entA);
appPrB = Double.parseDouble(appB);
soupPrB = Double.parseDouble(souB);
saladPrB = Double.parseDouble(salB);
entreePrB = Double.parseDouble(entB);
//the totals
totalA = appPrA + soupPrA + saladPrA + entreePrA;
totalB = appPrB + soupPrB + saladPrB + entreePrB;
//the Bill
JOptionPane.showMessageDialog(
null, nameA + "'s Bill \n" + "\n" + appYesA + " -$"+ appA + "\n"
+ soupYesA + " -$"+ souA + "\n"
+ saladYesA + " -$"+ salA + "\n"
+ entreeYesA + " -$"+ entA + "\n" + "\n"
+ "The Total before tax: $" + (totalA) + "\n"
+ "The Total after tax: $" + (1.07+(totalA)) + "\n"
,"The Tab",
JOptionPane.PLAIN_MESSAGE);
JOptionPane.showMessageDialog(
null, nameB + "'s Bill \n" + "\n" + appYesB + " -$"+ appB + "\n"
+ soupYesB + " -$"+ souB + "\n"
+ saladYesB + " -$"+ salB + "\n"
+ entreeYesB + " -$"+ entB + "\n" + "\n"
+ "The Total before tax: $" + totalB + "\n"
+ "The Total after tax: $" + (1.07+(totalB)) + "\n","The Tab",
JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}