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

Write a java program that adds up the squares and adds up the cubes of integers...
Write a java program that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered by the user: Upper Limit: 5 The sum of Squares is 55 The sum of Cubes is 225 Do this by using just one loop that generates the integers. DO NOT USE ANY FORMULAS.
***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...
When the user enters 4 at the menu prompt, your program will access all objects in...
When the user enters 4 at the menu prompt, your program will access all objects in the array to calculate and display only the largest number of coin denomination, and the total number of coins for the largest denomination. If there are more than one coin denominations having equal amount, you will need to list down all of them. After processing the output for menu option 4, the menu is re-displayed. Menu option 4 should return as follows. The largest...
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...
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
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT