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

Original Program : (assingment builds off of it): import java.util.Scanner; impo

ID: 3554820 • Letter: O

Question

Original Program: (assingment builds off of it):

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

public class Assign9
{
public static void main(String [] args)
{
    final double TAX_RATE_1 = 0.0125,         
                 TAX_RATE_2 = 0.0225,
                 TAX_RATE_3 = 0.0325,
                 TAX_RATE_4 = 0.05;
  
    int choice;
  
    int countItems = 0;

    double grandTotals = 0;
  
    double price,                             
           salesTax,
           total;
  
    Scanner keyScan = new Scanner(System.in);   
  
    DecimalFormat currency = new DecimalFormat("$#,###,##0.00");
  
    System.out.print("Welcome to the CSCI 210 Pricing System");
  
    do
    {
  
      System.out.print(" Please enter the item's price: ");
      price = keyScan.nextDouble();
  
      if (price < 50.00)
    
        salesTax = price * TAX_RATE_4;
  
      else if (price < 100.00)
    
        salesTax = price * TAX_RATE_3;
  
      else if (price < 200.00)
    
        salesTax = price * TAX_RATE_2;
  
      else
    
        salesTax = price * TAX_RATE_1;
  
      total = price + salesTax;
  
      System.out.printf("         Price: %13s", currency.format(price));
    
      System.out.printf("     Sales Tax: %13s", currency.format(salesTax));
    
      grandTotals += total;
    
      System.out.print ("                -------------");
    
      System.out.printf("         Total: %13s", currency.format(total));
    
      System.out.print(" Please enter a '1' if you want to do another: ");
    
      choice = keyScan.nextInt();
  
    }
    while(choice == 1);
  
     System.out.println(" countItems = " + countItems);

     System.out.println(" grandTotals = " + grandTotals);
    
     System.out.print(" Thank you for using the Pricing System! ");

}
}

Question:

Copy your program you wrote for Assignment 9 and rename the file Assign10.java and the class Assign10.

Also, copy the attached orders.txt file into the SAME folder on your flash drive, PC, laptop or Mac where you have saved your Assign10.java program file. (This is critical!) Each line, or record, in the orders.txt file will have the customer's name followed by at least one space and then the price of their order in dollars and cents. Here are several examples of what the records in the file might look like:

Abraham_Lincoln 34.59
Charles_Lindbergh 12.99
James_A._Garfield 99.32
Ulysses_S._Grant 103.12
Susan_B._Anthony 243.99
Martha_Washington .99

With this program, we are going to change the program logic to read the data from an input text file instead of asking the user to enter data. To do this, you need to add the following import statement to the other two import statements already included in your program:

import java.io.*;

You will also need to change the Scanner object declaration from System.in to point to the orders.txt file where the data is stored. How to do this has been illustrated several times in class and is also shown in a sample Java program in the appropriate folder in Blackboard's Slides & Notes.
  
You will now change the do while loop to a while loop and use hasNext() as the condition to end your while loop.

At the top of the while loop and right after your increment the counter, read the customer's name using next(), store it in the String variable named customerName and display it as before.

The next thing your program should do is read the price from the record and, of course, store it in your double variable named price.
  
Calculate sales tax and total as before, display the values as before and, finally, add the total to the grand totals as before.
  
Once again, after the loop ends but before the good-bye (trailer) message, display the value in the counter variable and, on a second double-spaced line, display the grandTotal.
  

Explanation / Answer

/* OUTPUT

*/

import java.util.Scanner;
import java.text.DecimalFormat;
import java.io.*;
public class Assign10
{
public static void main(String [] args) throws FileNotFoundException
{
    final double TAX_RATE_1 = 0.0125,       
                 TAX_RATE_2 = 0.0225,
                 TAX_RATE_3 = 0.0325,
                 TAX_RATE_4 = 0.05;
    int choice;
    int countItems = 0;
    double grandTotals = 0;
    double price,                           
           salesTax,
           total;
   //Scanner keyScan = new Scanner(System.in);
   Scanner keyScan = new Scanner(new File("orders.txt"));
   DecimalFormat currency = new DecimalFormat("$#,###,##0.00");
    System.out.print("Welcome to the CSCI 210 Pricing System");
    String customerName;
    //do
   while(keyScan.hasNext())
    {
      //System.out.print(" Please enter the item's price: ");
      countItems++;
      customerName = keyScan.next();
      System.out.println("Customer name is " + customerName);
      price = keyScan.nextDouble();
      if (price < 50.00)
        salesTax = price * TAX_RATE_4;
      else if (price < 100.00)
        salesTax = price * TAX_RATE_3;
      else if (price < 200.00)
        salesTax = price * TAX_RATE_2;
      else
        salesTax = price * TAX_RATE_1;
      total = price + salesTax;
        System.out.printf("         Price: %13s", currency.format(price));
        System.out.printf("     Sales Tax: %13s", currency.format(salesTax));
        grandTotals += total;
      System.out.print ("                -------------");
        System.out.printf("         Total: %13s", currency.format(total));
        //System.out.print(" Please enter a '1' if you want to do another: ");
        //choice = keyScan.nextInt();
     }
     System.out.println(" countItems = " + countItems);
     System.out.println(" grandTotals = " + grandTotals);
     System.out.print(" Thank you for using the Pricing System! ");
}
}

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