Compute gross as hours times rate display name hours rate


Create a payroll program. Enter Name, Hours and rate. Compute gross as Hours times Rate. Display Name, Hours Rate and Gross. Use Scanner class for your input and JOption as well as System.out.println for your output.

I have this code but am not sure why JOptionPane does not work

import java.util.Scanner;

import javax.swing.JOptionPane;

public class PayrollProg

{

  public static void main(String[] args)

  {

  Scanner input = new Scanner(System.in);

  double hourlyRate;

  double hoursWorked;

  double grossPay;

  System.out.print("Employee name: ");

  String employeeName = input.nextLine();

  System.out.printf("Enter hourly rate for %s: $", employeeName);

  hourlyRate = input.nextDouble();

  while (hourlyRate < 0.00)

  {

  System.out.print("Please only enter positive numbers: $");

  hourlyRate = input.nextDouble();

  }

  System.out.printf("Total hours worked: ");

  hoursWorked = input.nextDouble();

  while (hoursWorked < 0.00)

  {

  System.out.print("Please only enter positive numbers: ");

  hoursWorked = input.nextDouble();

  }

  grossPay = hourlyRate * hoursWorked;

  System.out.printf("Gross Pay: $%.2fn", grossPay);

  System.out.println();

  }

  {

  JOptionPane.showMessageDialog (null, "The gross pay for %s is ", grossPay);

  }

}

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Compute gross as hours times rate display name hours rate
Reference No:- TGS02658794

Now Priced at $10 (50% Discount)

Recommended (92%)

Rated (4.4/5)