174k views
2 votes
Your solution must include some kind of a product class with a name, category, description, and price for each item.

• 4 items minimum; stored in a list.
• Present a menu to the user and let them choose an item (by number or letter).
• Allow the user to choose a quantity for the item ordered.
• Give the user a line total (item price * quantity).
• Either through the menu or a separate question, allow them to re-display the menu and to complete the purchase.
• Give the subtotal, sales tax, and grand total. (Remember rounding issues the Math library will be handy!) • Ask for payment type—cash, credit, or check • For cash, ask for amount tendered and provide change.
• For check, get the check number.
• For credit, get the credit card number, expiration, and CVV.
• At the end, display a receipt with all items ordered, subtotal, grand total, and appropriate payment info.
• Return to the original menu for a new order. (Hint: you’ll want an array or List to keep track of what’s been ordered!)
• (Moderate) Store your list of products in a text file and then include an option to add to the product list, which then outputs to the product file.

User Smoe
by
8.5k points

1 Answer

2 votes

Final answer:

To calculate a total purchase amount, include sales tax by multiplying the total cost by the tax rate. For additional charges like tips, multiply by the desired percentage. Provide payment details as required for credit, cash, or check transactions.

Step-by-step explanation:

Understanding Sales Tax and Totals

When calculating the total amount due for a purchase, it is crucial to include the sales tax and any additional charges such as a tip when applicable. For instance, if a restaurant bill is $47.50 and a 6% sales tax is applied, we first calculate the tax amount by converting the percentage to a decimal and multiplying by the bill amount. This can be calculated as $47.50 x 0.06, resulting in $2.85. Adding this to the original amount gives us the taxed total which is $47.50 + $2.85 = $50.35.

If a tip is given at the rate of 20%, it is similarly calculated based on the pre-tax amount, $47.50. Therefore, the tip would be $47.50 x 0.20 = $9.50. The overall total, including sales tax and tip, will then be the sum of the initial amount, tax, and tip: $47.50 + $2.85 + $9.50 = $59.85. If paying by credit card, the payer would need to provide their card number, expiration date, and CVV to complete the transaction.

For other scenarios, such as purchasing a $150 item with a 10% sales tax, one would calculate the tax as $150 x 0.10 to get $15.00 for tax. The total payment would then be $150 + $15.00 = $165.00. It's important to factor in all aspects to avoid being surprised at the register, and for cash transactions, ensure you get the correct change back.

User MrDustpan
by
8.4k points