Answer to Question #278562 in Java | JSP | JSF for Dreaper

Question #278562

Write a simple payroll program that will display the employee’s information. The program should perform

the following:

  • Ask the user to enter the name of the employee.
  • Prompt the user to select between full time and part time by pressing either F (full time) or P
  • (part time)
  • If F is pressed, ask the user to enter his monthly salary. Then display his name and salary.
  • If P is pressed, ask the user to type his rate (pay) per hour, the number of hours he worked, and the numbers of overtime.
  • Then display his name and wage. The computation of overtime pay is: ℎ × ( ℎ × 125%)
  • If an invalid letter is pressed, display an error message.
1
Expert's answer
2021-12-12T01:17:41-0500
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter the name: ");
        String name = in.nextLine();
        System.out.print("F(full time) or P(part time): ");
        String type = in.nextLine();
        if (type.equals("F")) {
            System.out.print("Enter your monthly salary: ");
            double salary = in.nextDouble();
            System.out.println(name + " $" + salary);
        } else if (type.equals("P")) {
            System.out.print("Rate: ");
            double rate = in.nextDouble();
            System.out.print("The number of hours you worked: ");
            double hours = in.nextDouble();
            System.out.print("The numbers of overtime: ");
            double overtime = in.nextDouble();
            System.out.println(name + " $" + (rate * hours + rate * 1.25 * overtime));
        } else {
            System.out.println("Invalid input.");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS