Details: Payroll Program that: Displays text that requests the user to 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 must continue to request employee information until the user enters “stop” as the employee name. The application should be programmed to check that the hourly rate and number of hours worked are positive numbers. If either the hourly rate or the number of hours worked is not a positive value, the application should prompt the user to enter a positive amount. The application uses a class to store and retrieve the employee’s name, the hourly rate, and the number of hours worked. Use a constructor to initialize the employee information, and a method within that class to calculate the weekly pay. Once stop is entered as the employee name, the application should terminate.

The Payroll Program described above aims to create an application that allows the user to input employee information, such as the name, hourly rate, and number of hours worked, and then calculate and display the weekly pay amount for each employee. The program should prompt the user to input the necessary information, validate that the hourly rate and number of hours worked are positive numbers, and continue to request employee information until the user enters “stop” as the employee name. The weekly pay amount should be formatted to display currency and a dollar symbol should be included.

To accomplish this, the program should utilize a class to store and retrieve the employee’s name, hourly rate, and number of hours worked. A constructor within this class can be used to initialize the employee information, and a method can be created to calculate the weekly pay.

The first step in implementing this program is to create a class that represents an employee. The class should have instance variables to store the employee’s name, hourly rate, and number of hours worked. It should also include a constructor to initialize these variables.

“`java
public class Employee {
private String name;
private double hourlyRate;
private double hoursWorked;

public Employee(String name, double hourlyRate, double hoursWorked) {
this.name = name;
this.hourlyRate = hourlyRate;
this.hoursWorked = hoursWorked;
}
}
“`

Next, a method should be added to the `Employee` class to calculate the weekly pay amount. This can be done by multiplying the hourly rate by the number of hours worked.

“`java
public class Employee {
// previous code

public double calculateWeeklyPay() {
return hourlyRate * hoursWorked;
}
}
“`

Now that the `Employee` class is complete, the main program logic can be implemented to prompt the user for employee information, validate the input, and display the weekly pay amount. The program should continue to request employee information until the user enters “stop” as the employee name.

“`java
import java.util.Scanner;

public class PayrollProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String employeeName;

do {
System.out.print(“Enter employee name (or ‘stop’ to terminate): “);
employeeName = scanner.nextLine();

if (!employeeName.equalsIgnoreCase(“stop”)) {
System.out.print(“Enter hourly rate: “);
double hourlyRate = scanner.nextDouble();

System.out.print(“Enter number of hours worked: “);
double hoursWorked = scanner.nextDouble();

if (hourlyRate > 0 && hoursWorked > 0) {
Employee employee = new Employee(employeeName, hourlyRate, hoursWorked);
double weeklyPay = employee.calculateWeeklyPay();
System.out.printf(“Weekly pay for %s: $%.2f%n”, employeeName, weeklyPay);
} else {
System.out.println(“Hourly rate and number of hours worked must be positive numbers. Please try again.”);
}

// Consume newline character from scanner
scanner.nextLine();
}
} while (!employeeName.equalsIgnoreCase(“stop”));

System.out.println(“Program terminated.”);
}
}
“`

In this program, a `Scanner` object is used to read input from the user. A `do-while` loop is utilized to repeatedly prompt the user for employee information until “stop” is entered as the employee name. The input for the hourly rate and number of hours worked are validated to ensure they are positive numbers. If the input is valid, an instance of the `Employee` class is created, the weekly pay amount is calculated using the `calculateWeeklyPay` method, and the result is displayed to the user. Finally, when “stop” is entered as the employee name, the program terminates and displays a message indicating this.

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer