Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your task is to write a program that will calculate the total bill of a customer

ID: 3745262 • Letter: Y

Question

Your task is to write a program that will calculate the total bill of a customer after purchasing 3 items from the grocery store. This assignment builds on 2 key concepts from the last assignment

1. Unlike your last assignment , this time the name, quantity and cost per unit item must be input from the user, instead of being hardcoded. You must also input the sales tax from the user. Once you have input the items from the user and stored them into appropriate variables, the actual calculation is similar to the last assignment.

2. Your program must display a table consisting of

A) Name of the item

B) Cost per unit

C) Quantity

for each item. At the end of this table, you should display a line with the total sales tax, and a line displaying the total bill amount. All number MUST be rounded upto 2 decimal places.

SAMPLE INPUT/OUTPUT

Enter name of item : Apples

Enter cost per unit of item : 0.57

Enter quantity of item : 5

Enter name of item : Milk

Enter cost per unit of item : 1.89

Enter quantity of item : 4

Enter name of item : Chicken

Enter cost per unit of item : 2.49

Enter quantity of item : 5.67

Enter Sales tax (%); 0.06

Item Quantity Cost

---------------------------------------

Apples 5.00 0.57

Milk   4.00 1.89

Chicken 5.67 2.49

Sales tax : $1.47

---------------------------------------

Total Bill : $26.00

---------------------------------------

Hints

1. You should have 3 new variables of type "String" to store the name of the items (in addition to the variables you used last time).

2. Think about how to output the data in the table. (System.out.format) . All numbers should be rounded upto 2 decimal places.

3. You may assume the item name will not exceed 10 characters, and any number/fraction that you input will not exceed 10 digits, including the decimal part.

Explanation / Answer

import java.util.Scanner; public class ItemsTable { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter name of item : "); String name1 = in.next(); System.out.print("Enter cost per unit of item : "); double cpi1 = in.nextDouble(); System.out.print("Enter quantity of item : "); double q1 = in.nextDouble(); System.out.print("Enter name of item : "); String name2 = in.next(); System.out.print("Enter cost per unit of item : "); double cpi2 = in.nextDouble(); System.out.print("Enter quantity of item : "); double q2 = in.nextDouble(); System.out.print("Enter name of item : "); String name3 = in.next(); System.out.print("Enter cost per unit of item : "); double cpi3 = in.nextDouble(); System.out.print("Enter quantity of item : "); double q3 = in.nextDouble(); System.out.print("Enter Sales tax (%); "); double tax = in.nextDouble(); System.out.println("Item Quantity Cost"); System.out.println("---------------------------------------"); System.out.printf("%s %.2f %.2f ", name1, q1, cpi1); System.out.printf("%s %.2f %.2f ", name2, q2, cpi2); System.out.printf("%s %.2f %.2f ", name3, q3, cpi3); System.out.println("---------------------------------------"); double bill = ((q1*cpi1) + (q2*cpi2) + (q3*cpi3)) * (1+tax); System.out.printf("Total Bill : $%.2f ", bill); } }