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

Fill the program that reads the name, quantity, and price of three items from a

ID: 670138 • Letter: F

Question

Fill the program that reads the name, quantity, and price of three items from a text file “Catalog.txt”.
The name may not contain spaces. Output a bill with a tax rate of 6.25%. All prices should be output to two decimal places. The bill should be formatted in columns with
30 characters for the name, 10 characters for the quantity, 10 characters for the
price, and 10 characters for the total. Sample input and output is shown as follows:
Input:
Lollipops 10 0.50
dietsoda 3 1.25
chocolate bar 20 0.75
Item Quantity Price Total
lollipops 10 0.50 5.00
dietsoda 3 1.25 3.75
chocolatebar 20 0.75 15.00
SubTotal 23.75
6.25% Sales Tax 1.48
Total 25.23

Explanation / Answer

package mani;
import java.io.File;

import java.io.FileNotFoundException;

import java.text.DecimalFormat;
import java.util.Scanner;

public class CatalogTester
{

public static void main(String[] args) throws FileNotFoundException
{


String name ="";
int quantity = 0;
double price =0;
double total = 0;
double subtotal = 0;
double tax = 0;
double total_all = 0;

File inFile = new File("C:\Users\MANIKANTA Reddy\workspace\chegg\src\mani\Catalog.txt");
Scanner in = new Scanner(inFile);
System.out.printf("%-30s %-10s %-10s %-10s ", "Item", "Quantity","Price", "Total");
  
  
while(in.hasNext()){
name = in.next();
quantity = in.nextInt();
price = in.nextDouble();
total=price*quantity;
subtotal=subtotal+total;
System.out.printf("%-30s %-10d %-10.2f %-10.2f ", name, quantity, price, total);
}
in.close();
tax = subtotal * 0.0625;
total_all = subtotal+tax;
DecimalFormat df2 = new DecimalFormat("###.##");
System.out.println("Sub Total: "+subtotal);
tax=Double.valueOf(df2.format(tax));
System.out.println("6.25% Sales tax "+tax);

total_all=Double.valueOf(df2.format(total_all));
System.out.println("Total: "+total_all);

  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote