Program should read in a file called “sales.txt”. The contents of the text file are below. Create the sales.txt file with the following data: 10 100.00 9 18.18 100 50.00 64 121.22 560 1020.00 Read in all data from the file. (refer to pages 102-103) Sore units in integers and store sales in doubles. The first integer is the first unit sales. The first double is the first $ of all the sales combined. This continues through all five units. Utilize a constant called taxRate to hold the tax rate of 8.5%. Output the following items per the sample below: Total Unit Sales (the sum of all units) Total Sales (the sum of all sales) Total Tax (rounded) (sales times taxRate) Type cast to int * 100, then double / 100. Total Sale (not rounded) (sales plus tax) Output results in table format using the escape character for a tab as shown in the sample. Round the sales tax using basic math to round it. Do NOT use printf or any rounding function to perform this. Here is a few hints that I got.
So the tax rate is a double as you know. What you need to do is convert it to an integer first by multiplying by 100 and storing as integer. Then convert it back to a double and store it as a double. What this does is round it by getting rid of anything that is going to be over 2 decimal places. This is what I have so far. I just need the Total Tax and Total Sales . This is what I have so far. import java.util.Scanner; import java.io.File; public class SalesTax { public static void main (String[] args) throws Exception { //Scanner stdIn = new Scanner(System.in); Scanner stdIn = new Scanner (new File ("sales.txt")); int fUnit = stdIn.nextInt(); // First number of units double fPrice = stdIn.nextDouble(); // First Unit Price int sUnit = stdIn.nextInt(); // Second number of units double sPrice = stdIn.nextDouble(); // Second Unit Price int tUnit = stdIn.nextInt(); // Third number of units double tPrice = stdIn.nextDouble(); // Third Unit Price int foUnit = stdIn.nextInt(); // Fourth number of units double foPrice .nextDouble(); // Fourth Unit Price int fiUnit = stdIn.nextInt(); // Fifth number of units double fiPrice .nextDouble(); // Firth Unit price double taxRate= 0.085; double TotalSales = (fPrice + sPrice+ tPrice + foPrice + fiPrice); double TotalTaxes = (TotalSales * taxRate); double GrandTotal = (TotalSales + TotalTaxes); System.out.println("TotalUnits = t" + (fUnit + sUnit + tUnit + foUnit + fiUnit)); System.out.println("TotalSales = t$" + (fPrice + sPrice+ tPrice + foPrice + fiPrice)); System.out.println("TotalTaxes =t$" + (TotalSales * taxRate)); System.out.println ("GrandTotal=t$" + (TotalSales + TotalTaxes)); }// end main }// SalesTax
Get Free Quote!
257 Experts Online