- 12, May 2024
- #1
import java.util.Scanner;
import javax.swing.JOptionPane;
public class Homework_Four {
static Scanner scan = new Scanner(System.in);
//declaring variables
private static String name,jOptionInput;
private static int menuChoice,quantity,totalQuantity=0;
private static double price=0,saleTax=0,totalAmount;
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run(){
//entering name
System.out.print("Please enter your name: ");
name=scan.nextLine();
System.out.println(" ");
//Printing the menu
System.out.println("MENU");
System.out.println("1. Face painting $50");
System.out.println("2. Balloon twisting $45");
System.out.println("3. Puppet shows $55");
System.out.println("4. Stilt walkers $60");
System.out.println("5. Bounce house $80");
System.out.println("6. Rock wall $70");
System.out.println("7. Petting zoo $65");
System.out.println("10. Exit");
System.out.println(" ");
//using loop to read the selected menu and the quanity and exit when ten is entered
while(true)
{
System.out.print("Please select your options: ");
menuChoice =scan.nextInt();
if(menuChoice==10){break;}
jOptionInput = JOptionPane.showInputDialog(null,"How many hours would you like?","Number of hours",JOptionPane.INFORMATION_MESSAGE);
quantity = Integer.parseInt(jOptionInput);
//call method calculateCost to calculate cost
totalQuantity=totalQuantity+quantity;
calculateCost(menuChoice,quantity);
}
//getting the sale tax and total amount
saleTax =price*(0.065);
totalAmount=price+saleTax;
//printing the displays a receipt of this information
System.out.println();
System.out.println("Thank you for ordering with Fantasy Entertainment, "+name);
System.out.println("Total items ordered: "+totalQuantity);
System.out.println("Price of food ordered: $"+price);
System.out.println("Sales tax: $"+saleTax);
System.out.println("Total amount due: $"+totalAmount);
System.out.println("You saved: $"+ );
}});}
public static void calculateCost(int menu, int quantity ){
//calculating sale cost
switch(menu)
{
case 1:
price=price+(quantity*50);
break;
case 2:
price=price+(quantity*45);
break;
case 3:
price=price+(quantity*55);
break;
case 4:
price=price+(quantity*60);
break;
case 5:
price=price+(quantity*80);
break;
case 6:
price=price+(quantity*70);
break;
case 7:
price=price+(quantity*65);
break;
default:
break;
}
}
}
PHP:
I went another way with it. I need to do the following for the very last output which is "You saved: $"
There two promotions which are:
- if you select Face painting and balloons --> $10 off
- if you select all options --> $80 off