Question

In: Computer Science

You are writing a billing program that adds up the items a user enters. Your program...

You are writing a billing program that adds up the items a user enters. Your program should use a loop and prompt the user for the item number for each item in inventory to add to the bill. (You can ask the user for the number of items you will enter and use a counter controlled loop or a sentinel controlled loop that has a stop number. Either way is fine.) Here is the table of items in inventory:

Item Value

1 209.00
2 129.50
3 118.00
4 232.00

(So if your program starts asking the user for the items they are purchasing and they enter item 2 with quantity 2, and item 3 with quantity 1. The bill should be 377.00. On the next run if your program asks the user for items in the loop and they give enter each item with quantity of 1. The bill should be 688.50

[You must use an IF or IF/Else Structure to look up the item value for the item number they give or you are missing an objective on this assignment.] Use Java and NetBeans *.0 version to solve this. Must use a simple loop and nested if statement.

Solutions

Expert Solution

Answer:

import java.util.Scanner;

public class CalculateBill {
    public static void main( String[] args ) {
        int item,qty;
        double price=0,total_price=0;
        char choice;
        do{
            Scanner s=new Scanner(System.in);
            System.out.println("\nEnter the item no : ");
            item=s.nextInt();
            System.out.println("\nEnter the total no of items : ");
            qty=s.nextInt();

            //Assign each item price in the inventory according to the item no
            //and multiply the quantity of the items with the price
            if(item==1)
            {
                price=209.00 * qty;
            }
            else if(item==2)
            {
                price=129.50 * qty;
            }

            else if(item==3)
            {
                price=118.00 * qty;
            }

            else if(item==4)
            {
                price=232.00 * qty;
            }

            //add the total price in the end
            total_price+=price;
            
            //Ask the user user continuously if they want to add another item or not
            System.out.println("\nDo you want to add another item? \nPress Y or N");
            choice=s.next().charAt(0);
        }
       while(choice=='Y' || choice=='y' );



        System.out.println("\nYour Total Bill is: "+total_price);


    }

}

Output:


Related Solutions

***USING JAVA Scenario: You will be writing a program that will allow a user to find...
***USING JAVA Scenario: You will be writing a program that will allow a user to find and replace misspelled words anywhere in the phrase, for as many words as the user wishes. Once done (see example runs below), the program will print the final phrase and will show the Word Count, Character Count, the Longest Word and the Shortest Word. Requirements: Do not use Arrays for this assignment. Do not use any String class methods (.phrase(), replace methods, regex methods)...
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The program will now be broken up into methods and store all the inventory in an ArrayList object. The program will be able to run a report for all inventory details as well as a report for items that are low in...
Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The Food and Book items should inherit all the properties of the Product item in the previous assignment. Foods cannot be added to the inventory without an expiration date. Implement a toString method for Product, Food, and Book. Grading details: Correct usage...
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: Output the sum of all even numbers Output the sum of all odd numbers Output the count of all even numbers Output the count of all odd numbers You must use loops and numbers to do this. You must not use any arrays or vectors for this program.
Write a C++ program that reads numbers from the user until the user enters a Sentinel....
Write a C++ program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input (other than the sentinel). Do the following: 1. Output the sum of all even numbers 2. Output the sum of all odd numbers 3. Output the count of all even numbers 4. Output the count of all odd numbers You must use alternation ('if' statements), loops and simple calculations to do...
Please write the UML sequence diagrams for a shopping cart: User Logs In Customer Adds Items...
Please write the UML sequence diagrams for a shopping cart: User Logs In Customer Adds Items to Shopping Cart Customer Reviews Product Details Customer Reviews/Updates Shopping Cart Customer Checks Out Seller Reviews/Updates Inventory Seller Adds New Product
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user...
C++ code Inventory Item Stack You are writing an Inventory program that will allow the user to enter a part into the inventory, take a part from the inventory, or quit. You are provided with the InvItem class (InvItem.h) and a partial Driver.cpp. You will be creating a DynamicStack class that should implement a Stack data structure. The DynamicClass should be implemented as a template class to allow any data type be added/removed from the stack. You will submit three...
Write an application that accepts up to 20 Strings, or fewer if the user enters the...
Write an application that accepts up to 20 Strings, or fewer if the user enters the terminating value ZZZ. Store each String in one of two lists—one list for short Strings that are 10 characters or fewer and another list for long Strings that are 11 characters or more. After data entry is complete, prompt the user to enter which type of String to display, and then output the correct list. For this exercise, you can assume that if the...
1/Write a C program that asks the user to enter 5 nums and adds each number...
1/Write a C program that asks the user to enter 5 nums and adds each number to a total. The program should then display the total. To add to the total, the program must call the function void sum(int value, int *ptotal) passing the value the user entered and the address of the total (a local variable in main). The function should add the value to the total. Note that the function is void and does not return anything. Don't...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT