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
I've got netbeans but I haven't downloaded all the java components so I'm just going to have to read and see what I find. Starting with your function calculateCost - it doesn't return a value when it's called and you have nothing to catch it either: calculateCost(menuChoice,quantity); Is it setting a global variable? Two lines down you use price: saleTax =price*(0.065); If you are setting an object's properties don't you have to refer to "this"?
This is your homework - and you're up to assignment 4. Go back and read your lecture notes and see how you should be referring to properties. If you can't take a suggestion and use trial and error to find out if it might be pointing you in the right direction then you won't get far with programming.