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

Write a Java application that prompts a user for a fist name and a last name, an

ID: 3583013 • Letter: W

Question

Write a Java application that prompts a user for a fist name and a last name, and then asks if a user is a company’s employee. If positive – prompt for an hourly pay rate and hours worked. Compute the gross pay (hours times rate), withholding tax, and net pay ( gross pay minus withholding tax). Withholding tax should be computed as percentage of gross pay based on the following scale:

Gross Pay

Withholding Percentage

0 to 300.00

8%

300.01 to 400.00

10%

400.01 to 500.00

12%

500.01 and over

15%

Display the user’s name (first and last), hourly rate, hours worked, withholding tax percentage, withholding tax and gross pay.

When a user is not an employee – display the proper message on that and terminate the application.

Use logical AND and OR operators when designing the logic of the application.

Gross Pay

Withholding Percentage

0 to 300.00

8%

300.01 to 400.00

10%

400.01 to 500.00

12%

500.01 and over

15%

Explanation / Answer

CalculateSal.java

import java.util.Scanner;

public class CalculateSal {

   public static void main(String[] args) {
      
       //Declaring variables
       String firstname,lastname;
       int hourly_payRate,hours_worked,withholding_Tax_Percentage = 0;
       boolean companyEmployee;
       double withHolding_tax = 0,net_pay,gross_pay;
      
       //Scanner class object is used to read the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       //Getting the firstname entered by the user
System.out.print("Enter the firstname :");
firstname=sc.next();
  
//Getting the lastname entered by the user
System.out.print("Enter the lastname :");
lastname=sc.next();
  
//Getting whether the employee is Company Employee or not
System.out.print("Is the user is a company Employee(true/false) ? :");
companyEmployee=sc.nextBoolean();
  
//If the employee is company employee
if(companyEmployee==true)
{
   //Getting the pay rate entered by the user
   System.out.print("Enter Hourly Pay rate :$");
   hourly_payRate=sc.nextInt();
  
   //getting the hour worked entered by the user
   System.out.print("Enter Hours Worked :");
   hours_worked=sc.nextInt();
  
   //calculate the withholding tax
   gross_pay=hours_worked*hourly_payRate;
  
  
   //Based on the gross pay calculate the with holding tax
   if(gross_pay>=0 && gross_pay<=300)
   {
       withholding_Tax_Percentage=8;
       withHolding_tax=gross_pay*0.08;
   }
   else if(gross_pay>=300.01 && gross_pay<=400)
   {
       withholding_Tax_Percentage=10;
   withHolding_tax=gross_pay*0.1;
   }
   else if(gross_pay>=400.01 && gross_pay<=500)
   {
       withholding_Tax_Percentage=12;
   withHolding_tax=gross_pay*0.12;
   }
   else if(gross_pay>500.01 )
   {
       withholding_Tax_Percentage=15;
   withHolding_tax=gross_pay*0.15;
   }
  
   //Calculating the netpay
   net_pay=gross_pay-withHolding_tax;
  
  
   //Calculating the results
   System.out.println("Name :"+firstname+" "+lastname);
   System.out.println("Hourly Rate :$"+hourly_payRate);
   System.out.println("Hours Worked :"+hours_worked);
   System.out.println("WithHolding Tax Percentage :%"+withholding_Tax_Percentage);
   System.out.println("WithHolding Tax :$"+withHolding_tax);
   System.out.println("Gross Pay :$"+gross_pay);
  
  
}
else
{
   //Displaying the error message
   System.out.println("** The User "+firstname+" "+"is not an Employee **");
}
   }

}

_____________________

Output:

Enter the firstname :Kane

Enter the lastname :Williams
Is the user is a company Employee(true/false) ? :true
Enter Hourly Pay rate :$11
Enter Hours Worked :43
Name :Kane Williams
Hourly Rate :$11
Hours Worked :43
WithHolding Tax Percentage :%12
WithHolding Tax :$56.76
Gross Pay :$473.0

_______________

Output#2:

Enter the firstname :Michael
Enter the lastname :John
Is the user is a company Employee(true/false) ? :false
** The User Michael is not an Employee **

_________Thank You

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