Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

So this is supposed to be a simple ordering program but i cannot figure out why bill in my code screws up the total, individually

So this is supposed to be a simple ordering program but i cannot figure out why bill in my code screws up the total, individually the code comes out to the right numbers but bills case summs when it is not supposed to either with the prcursing individuals total or the next person, i think it has something to do with the if statement i have, it is the only thing different. p.s. per the lab promt these are the only people ordering and the order specific items i have mosted out put and code. thanks also i no the grand total is supposed to be 22.77 dollars

import java.util.Scanner; public class DinnerOut {

public static void main(String[] args) {

Scanner input =new Scanner(System.in); //declare nessecary variables double FinalAmount = 0; double individualTotal = 0; double subtotal = 0; //prompt the customers to enter the number of party members System.out.println("How many people will be dinning with your party?"); int partySize = input.nextInt();//party size will be used to control the loop cycle //instructions for the customers System.out.println("Thank you now please order individully and "+ "each member must order 3 items"); //loops that calculates the subtotals for each individual for (int i =1;i<= partySize;i++){ //prompt the customers to enter any discounts that may apply System.out.println("Please enter the name of customer ordering"); //based on input dicount is determined String Name = input.next(); switch (Name){ case "nancy": subtotal = Order(individualTotal);//no discount case individualTotal = subtotal+(subtotal*0.05); System.out.println(individualTotal); break; case "jesse": subtotal = Order(individualTotal);// childrem under 5 eat free individualTotal = 0; System.out.println(individualTotal); break; case "sara": subtotal = Order(individualTotal);// teens and seniors are not taxed and recieve 25% off individualTotal = subtotal-(subtotal*.25); System.out.println(individualTotal); break; case "bill": subtotal = Order(individualTotal);//no discount case individualTotal = subtotal+(subtotal*0.05); System.out.println(individualTotal); break; } FinalAmount += individualTotal;//summing up the entire total } //display the final amount due to 2 decimal places System.out.printf("the grand total due will be $"+ "%.2f", FinalAmount); input.close(); } //the method used to execute the individuals order public static double Order(double individualTotal){ Scanner input = new Scanner(System.in); //for loop for the 3 items to be ordered for (int j= 0; j<3;j++){ //initializing and declaring the arrays String[] itemName = {"item","1:Soup","2:Wings(per wing)","3:Burger","4:Chicken Sandwich","5:Fries","6:pie", "7:Ice Cream","8:Soft Drink","9:Coffee"}; double[] price ={0.0,2.50,.15,4.95,5.95,1.99,2.95,2.99,1.50,1.00}; //promt the customer to order System.out.println("Please make a selection from the menu below"+ " by enter the corresponding integer for that item such "+ "as 1 for soup"); //display the menu on the console System.out.println("Menuitem Price"); for (int i =0;i

} output

How many people will be dinning with your party?

4

Thank you now please order individully and each member must order 3 items

Please enter the name of customer ordering

nancy

Please make a selection from the menu below by enter the corresponding integer for that item such as 1 for soup

Menuitem Price

item $0.0

1:Soup $2.5

2:Wings(per wing) $0.15

3:Burger $4.95

4:Chicken Sandwich $5.95

5:Fries $1.99

6:pie $2.95

7:Ice Cream $2.99

8:Soft Drink $1.5

9:Coffee $1.0

3

Please make a selection from the menu below by enter the corresponding integer for that item such as 1 for soup

Menuitem Price

item $0.0

1:Soup $2.5

2:Wings(per wing) $0.15

3:Burger $4.95

4:Chicken Sandwich $5.95

5:Fries $1.99

6:pie $2.95

7:Ice Cream $2.99

8:Soft Drink $1.5

9:Coffee $1.0

8

Please make a selection from the menu below by enter the corresponding integer for that item such as 1 for soup

Menuitem Price

item $0.0

1:Soup $2.5

2:Wings(per wing) $0.15

3:Burger $4.95

4:Chicken Sandwich $5.95

5:Fries $1.99

6:pie $2.95

7:Ice Cream $2.99

8:Soft Drink $1.5

9:Coffee $1.0

1

9.397499999999999

Please enter the name of customer ordering

jesse

Please make a selection from the menu below by enter the corresponding integer for that item such as 1 for soup

Menuitem Price

item $0.0

1:Soup $2.5

2:Wings(per wing) $0.15

3:Burger $4.95

4:Chicken Sandwich $5.95

5:Fries $1.99

6:pie $2.95

7:Ice Cream $2.99

8:Soft Drink $1.5

9:Coffee $1.0

3

Please make a selection from the menu below by enter the corresponding integer for that item such as 1 for soup

Menuitem Price

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions