Purchase Solution

Question about A java program to read values and calculate payroll

Not what you're looking for?

Ask Custom Question

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?

Purchase this Solution

Solution Summary

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.

Solution Preview

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 ...

Purchase this Solution


Free BrainMass Quizzes
Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Networking Questions

This quiz consists of some basic networking questions.

C# variables and classes

This quiz contains questions about C# classes and variables.