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

Sam owns an auto repair shop and has several employees. He needs to write a simp

ID: 3796493 • Letter: S

Question

Sam owns an auto repair shop and has several employees. He needs to write a simple payroll program. If an employee works over 40 hours in a week, he gets paid 1.5 times their regular hourly pay rate for all hours over 40.

Sample output 1:

Enter the number of hours worked: 40
Enter the hourly pay rate: 20
You entered 40 hours.
The Gross Pay is $800.00.

Sample output 2:

Enter the number of hours worked: 50
Enter the hourly pay rate: 20
You entered 50 hours.
The Gross Pay is $1,100.00.

Notes:

Use Boolean Expressions and Relational Operators

Documentation - use proper indentation, comments, white space, and display appropriate messages

Input - prompt the user to enter hours worked and hourly rate

Calculation - if employee worked 40 hours or less, calculate the gross pay; else calculate the gross pay with overtime

Output - match with the provided sample

In the event that the expected outputs do not match the output tests or the code is incomplete that the program fails to run, points will be given to the sections that the codes are written properly


import java.text.DecimalFormat;
import java.util.Scanner;
// FIXME 1 (5 points): Import the class needed for taking user input
public class Payroll {
public static void main(String args[]) {

// FIXME 2 (10 points): Complete declaring the class and the main method; pay attention to the name of the class
{
  
  
   {
      
       // Define variables
       Scanner scnr = new Scanner(System.in);
       double hoursWorked = 0.0;
       double grossPay = 0.0;
       double hourlyRate = 0.0;
       double overTime = 1.5;
      
       /*
       FIXME 3 (10 points): Declare two other variables of double data type for the Hourly Pay Rate and the Overtime Multiplier;
       Note: the Overtime Multiplier (1.5) should be a constant variable
       */
       System.out.println("Enter the number hours worked: ");
       hoursWorked = scnr.nextDouble();
       System.out.println("Enter the hourly pay rate: ");
       hourlyRate = scnr.nextDouble();
      
      
       /*
       FIXME 4 (20 points): Write the statements to prompt the user to enter the Hours Worked and the Hourly Pay Rate
       (end with new line); Assign the values to the corresponding variables
       */
       if(hoursWorked >= 40) {
       System.out.println(hoursWorked * hourlyRate);
       }
       else {
       System.out.println((hourlyRate + overTime) * hoursWorked);
      
      
       /*
       FIXME 5 (50 points): Calculate the gross pay for 1) regular pay (20 of 50 points), and
       2) regular pay with overtime (30 of 50 points)
       */
      
      
      
       // Print gross pay
       // FIXME 6 (5 points): Correct the print statement below
       System.out.println("You entered " + hoursWorked + " hours.");
       System.out.println("The Gross Pay is " + customFormat("$###,###.00", grossPay) + ".");
      
   }

   private static String customFormat(String pattern, double d) {
       DecimalFormat myFormatter = new DecimalFormat(pattern);
       String output = myFormatter.format(d);
       return output;
   }
}
}


I keep getting these errors:

Payroll.java:55: error: illegal start of expression

Explanation / Answer

import java.text.DecimalFormat;
import java.util.Scanner;
// FIXME 1 (5 points): Import the class needed for taking user input
public class Payroll {
public static void main(String args[]) {

// FIXME 2 (10 points): Complete declaring the class and the main method; pay attention to the name of the class
      
        // Define variables
        Scanner scnr = new Scanner(System.in);
        double hoursWorked = 0.0;
        double grossPay = 0.0;
        double hourlyRate = 0.0;
        double overTime = 1.5;
      
        /*
        FIXME 3 (10 points): Declare two other variables of double data type for the Hourly Pay Rate and the Overtime Multiplier;
        Note: the Overtime Multiplier (1.5) should be a constant variable
        */
        System.out.println("Enter the number hours worked: ");
           hoursWorked = scnr.nextDouble();
        System.out.println("Enter the hourly pay rate: ");
           hourlyRate = scnr.nextDouble();
      
      
        /*
        FIXME 4 (20 points): Write the statements to prompt the user to enter the Hours Worked and the Hourly Pay Rate
        (end with new line); Assign the values to the corresponding variables
        */
        if(hoursWorked <= 40) {
           grossPay = hoursWorked * hourlyRate;
        }
        else {
           grossPay = 40*hourlyRate + (hoursWorked - 40)*1.5*hourlyRate;
      
        }
        /*
        FIXME 5 (50 points): Calculate the gross pay for 1) regular pay (20 of 50 points), and
              2) regular pay with overtime (30 of 50 points)
        */
      
      
      
      
        // Print gross pay
        // FIXME 6 (5 points): Correct the print statement below
        System.out.println("You entered " + hoursWorked + " hours.");
        System.out.println("The Gross Pay is " + customFormat("$###,###.00", grossPay) + ".");
      
    }

    private static String customFormat(String pattern, double d) {
        DecimalFormat myFormatter = new DecimalFormat(pattern);
        String output = myFormatter.format(d);
        return output;
    }
}


Output:

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