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

Create a non-GUI-based Java application that calculates weekly pay for an employ

ID: 3764455 • Letter: C

Question

Create a non-GUI-based Java application that calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency. The application also displays a bonus amount if the hours worked are more than 40. The bonus amount is the number of hours more than 40 times the hourly rate. You can assume that the employee works at least 40 hours each week.

(The application compiles and runs).
(The application displays text that requests the user input the name of the employee, the hourly rate, and the number of hours worked.)
(The application prints out the name of the employee and the correct weekly pay amount in dollar format.)

(The application displays the correct bonus amount in dollar format)
(The source code is readable and well documented)

Please make sure that your code also prints both the weekly salary and bonus amount if the hours worked are more than 40.

Explanation / Answer

import java.util.Scanner;

/**
*
*/

/**
* @author srinu calculates weekly pay for an employee
*/
public class WeeklySalary {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Scanner scanner = new Scanner(System.in);
       try {
           // requests the user input the name of the employee, the hourly
           // rate, and the number of hours worked.
           System.out.print("Enter the name of Employee:");
           String employeeName = scanner.nextLine();
           System.out.print("Hourly Rate : $");
           double hourRate = scanner.nextDouble();
           System.out.println("Number of hours worked :");
           int hoursWorked = scanner.nextInt();
           double weeklyPay = 0, bonusPay = 0;
           // caliculating weekly pay and bonus pay
           if (hoursWorked > 40) {
               // if hourly worked is more than 40
               // then The bonus amount is the number of hours more than 40
               // times the hourly rate
               weeklyPay = (double) hourRate * 40;
               bonusPay = (double) (hoursWorked - 40) * hourRate * 40;

           } else {

               weeklyPay = (double) hourRate * hoursWorked;

           }
           // name of the employee and the correct weekly pay amount in dollar
           // format and bonus amount in dollar format

           System.out.println("***WEEKLY PAY***");
           System.out.println("-----------------");
           System.out.println("Employee Name:" + employeeName);
           System.out.println("Weekly pay amount :$" + weeklyPay);
           if (bonusPay != 0) {
               System.out.println("Bonus amount :$" + bonusPay);
           }

       } catch (Exception e) {
           // TODO: handle exception
       } finally {
           scanner.close();
       }

   }

}

OUTPUT:

Enter the name of Employee:Srinivas
Hourly Rate : $32.33
Number of hours worked :45


***WEEKLY PAY***
-----------------
Employee Name:Srinivas
Weekly pay amount :$1293.1999999999998
Bonus amount :$6465.999999999999

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