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

JAVA (Beginner coding) Write a program to create a customer\'s bill for a compan

ID: 3664677 • Letter: J

Question

JAVA (Beginner coding)

Write a program to create a customer's bill for a company. The company sells only five different products: TV, VCR, Remote Controller, CD Player and Tape Recorder. The unit prices are $400.00, $220, $35.20, $300.00 and $150.00 respectively. The program must read the quantity of each piece of equipment purchased from the keyboard. It then, calculates the cost of each item, the subtotal and the total cost after an 8.25% sales tax. The input data consists of a set of integers representing the quantities of each item sold. These integers must be input into the program in a user- friendly way; that is, the program must prompt the user for each quantity as shown below -

How many TV's were sold? 3

How many VCR's were sold? 5

How many remote controller's were sold? 1

How many CD's were sold? 2

How many Tape Recorder's were sold? 4

The output of the program should print the following data properly formatted:

       QTY DESCRIPTION UNIT PRICE TOTAL PRICE

              ...

                           SUBTOTAL

                              TAX

TOTAL

Define constants for the unit prices and the tax rate. Use integer variables to store the quantities for each item. Use floating-point variables to store the total price of each item, the bill subtotal, the tax amount and and the total amount of the bill. Run your program two times with the following data:

Set 1 -> 2 1 4 1 2

Set 2 -> 3 0 2 0 21

Format the output adequately showing the 4 columns (QTY, DESCRIPTION, UNIT PRICE, TOTAL PRICE) in a single row. Use System.out.printf for output.

Explanation / Answer

As per given problem CustomerBill class is implemented with necessary costs and total costs and tax

See the below Code..

import java.util.*;

public class customerBill
{
    public static void main(String args[])
    {         
        final double tv_price = 400.0;
        final double vcr_price = 220.0;
        final double remote_price = 35.20;
        final double cd_price = 300.0;
        final double tape_price = 150.0;
        final double tax = 8.25;
      
        Scanner sc = new Scanner(System.in);
        System.out.println("How many TV's were sold?");
        int tv_quantity = sc.nextInt();

        System.out.println("How many VCR's were sold?");
        int vcr_quantity = sc.nextInt();

        System.out.println("How many remote controller's were sold?");
        int remote_quantity = sc.nextInt();

        System.out.println("How many CD's were sold?");
        int cd_quantity = sc.nextInt();

        System.out.println("How many Tape Recorder's were sold?");
        int tape_quantity = sc.nextInt();

        double tv_total_cost = tv_price * tv_quantity;
        double vcr_total_cost = vcr_price * vcr_quantity;
        double remote_total_cost = remote_price * remote_quantity;
        double cd_total_cost = cd_price * cd_quantity;
        double tape_total_cost = tape_price * tape_quantity;
        double total_cost = tv_total_cost + vcr_total_cost + remote_total_cost + cd_total_cost + tape_total_cost;
        double total_tax = total_cost * tax;
        double total_tax_cost = total_tax + total_cost;
      
        System.out.println("QTY        DESCRIPTION        UNIT        PRICE        TOTAL_PRICE");
        System.out.println(tv_quantity+"        "+"Television        "+"TV        "+tv_price+"        "+tv_total_cost);
        System.out.println(vcr_quantity+"        "+"Video Controller         "+"VCR        "+vcr_price+"        "+vcr_total_cost);
        System.out.println(remote_quantity+"        "+"Remote Controller        "+"Remote        "+remote_price+"        "+remote_total_cost);
        System.out.println(cd_quantity+"        "+"CD Player        "+"CD        "+cd_price+"        "+cd_total_cost);
        System.out.println(tape_quantity+"        "+"Tape Recorder        "+"Tape        "+tape_price+"        "+tape_total_cost);
       System.out.println();
        System.out.println("SUB TOTAL : "+total_cost);
        System.out.println("      TAX : "+total_tax);
        System.out.println("TOTAL COST: "+total_tax_cost);
        sc.close();
    }
}

Output: