Modify the Payroll Program application so it continues to request employee information until the user enters stop as the employee name. In addition, program the application 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 teacher posted that this is what the program should have looked like:
public class Payroll
public static void main (String args)
Scanner input = new Scanner(System.in);
System.out.print("Enter name: ");
name = input.next();
System.out.print("Enter payrate: "); // prompt
payRate = input.nextDouble();
System.out.print("Enter hours: "); // prompt
hours = input.nextDouble();
weeklyPay = payRate * hours;
System.out.print(name + " earned ");
System.out.printf("$ %.2fn", weeklyPay);
} //end of main method
} // end of Payroll class
Can you do the modifications and post the solution in the correct format, or tell me how I get it to the .java file extension?© BrainMass Inc. brainmass.com March 4, 2021, 8:29 pm ad1c9bdddf
We have two main things we have to add to the program provided in the question. First, we need to add a loop in the main function to continue asking for data until the user requests a stop. Second, we have to make sure that the values entered are positive.
In order to check that the values are positive we should have a routine that reads in the numbers. That way the details of doing that are not in the main function. The method to do this is:
// This method is a generic method to read in a positive number. The ...
This solution demonstrates how to write a Java program to read in valid integer values and calculate payroll information from them. There is some discussion in the solution to explain how the program works.