Explore BrainMass
Share

A java program to read values and calculate payroll

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

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.

© BrainMass Inc. brainmass.com October 24, 2018, 10:47 pm ad1c9bdddf
https://brainmass.com/computer-science/java/170910

Attachments

Solution Preview

The original file had several small bugs that needed to be fixed. These were mostly due to mistyped words (System.outprint instead of System.out.print, for example). Once those were fixed then the program mostly worked for reading in the information for one employee. The trick to getting the program to read for multiple employees is to use a loop that continues until a certain condition is met. In this case we want to use a while loop that will continue while the employee name is not "stop".

Also, notice that we are trying to read in a positive integer in two different locations. When that happens it is best to make ...

Solution Summary

This solution demonstrates how to read in integers and check that they have a valid value. It also show how to do some arithmetic operations on the numbers read in. This solution is in Java.

$2.19
See Also This Related BrainMass Solution

Question about A java program to read values and calculate payroll

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:
import java.util.Scanner;

public class Payroll
{
public static void main (String args[])
{

String name;
double payRate;
double hours;
double weeklyPay;

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?

View Full Posting Details