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

Note: The tax calculation in the SalesTax.java is incorrect. This is for student

ID: 3745025 • Letter: N

Question

Note: The tax calculation in the SalesTax.java is incorrect. This is for student to modify the program with the correct algorithm ( tax = price times the tax rate. total price should be the good's price plus tax).

1. Compile the Pay.java using the NetBeans or other Java IDE.

2. You should not receive any error messages.

3. When this program is executed, it will ask the user for input. You should test three different cases: the working hour >, <, and = 40 hours.

Note: you do not need to compile again. Once the program compiles correctly once, it can be executed many times. You only need to compile again if you make changes to the code.

//This program calculates the user's gross pay

import java.util.Scanner;     //to be able to read from the keyboard

public class Pay
{
   public static void main(String [] args)
   {
       //create a Scanner object to read from the keyboard
       Scanner keyboard = new Scanner(System.in);

       //identifier declarations
       double hours;   //number of hours worked
       double rate;   //hourly pay rate
       double pay;       //gross pay

       //display prompts and get input
       System.out.print("How many hours did you work? ");
       hours = keyboard.nextDouble();
       System.out.print("How much do you get paid per hour? ");
       rate = keyboard.nextDouble();
      
       //calculations
       if(hours <= 40)
           pay = hours * rate;
       else
           pay = (hours - 40) * (1.5 * rate) + 40 * rate;

       //display results
       System.out.println("You earned $" + pay);
   }
}

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

1. Open the file SalesTax.java in NetBeans or other Java IDE. This file contains a simple Java program that contains errors. Compile the program. You should get a listing of syntax errors. Correct all the syntax errors, you may want to recompile after you fix some of the errors. If you use NetBeans, the recompiling may be automatic.

2. When all syntax errors are corrected, the program should compile. As in the previous exercise, you need to develop some test data.

3. Execute the program using your test data and save a screen shot about the output. There is a logic error on this program. Examine the program and correct logic error. Compile the program and execute using the test data again.

Use the following test data to check your logical error:

//This program calculates the total price which includes sales tax

import java.util.Scanner;

public class SalesTax
{
   public static void main(String[] args)
   {
       //identifier declarations
       final double TAX_RATE = 0.055;
       double price;
       double tax
       double total;
       String item;
      
       //create a Scanner object to read from the keyboard
       Scanner keyboard = new Scanner(System.in);

       //display prompts and get input
       System.out.print("Item description: ");
       item = keyboard.nextLine();
       System.out.print("Item price: $");
       price = keyboard.nextDouble();
      
       //calculations
       tax = price + TAX_RATE;
       totl = price * tax;
      
       //display results
       System.out.print(item + " $");
       System.out.println(price);
       System.out.print("Tax $");
       System.out.println(tax);
       System.out.print("Total $");
       System.out.println(total);
   }
}

Explanation / Answer

Here is the corrected code for SalesTax.java. The Pay.java file is unchanged and it’s not clear that why you have included it in the question.

// SalesTax.java

import java.util.Scanner;

public class SalesTax {

      public static void main(String[] args)

   {

       //identifier declarations

       final double TAX_RATE = 0.055;

       double price;

       double tax;

       double total;

       String item;

     

       //create a Scanner object to read from the keyboard

       Scanner keyboard = new Scanner(System.in);

       //display prompts and get input

       System.out.print("Item description: ");

       item = keyboard.nextLine();

       System.out.print("Item price: $");

       price = keyboard.nextDouble();

     

       //calculations

       tax = price * TAX_RATE;

       total = price + tax;

     

       //display results

       System.out.print(item + " $");

       System.out.println(price);

       System.out.print("Tax $");

       System.out.println(tax);

       System.out.print("Total $");

       System.out.println(total);

   }

}

/*OUTPUT*/

Item description: Food

Item price: $200

Food $200.0

Tax $11.0

Total $211.0

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