CODE
// PayrollPartTwo.java
// payroll that displays an employee name, hours worked, pay rate and total weekly pay.
import java.util.Scanner; // required for keyboard input
public class PayrollPartTwo
{
// main method begins execution of java application
public static void main(String args[] )
{
// Create a Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
String employeeName; //The name of the employee
String cleanInputBuffer; //For cleaning the input buffer
double hourlyWageInDollars = 0.0; //The employee wage in dollars
double hoursWorkedInWeek = 0.0; //The Hours worked in the week
double weeklyWageInDollars = 0.0; //The employee's pay for the week
while ( true )
{
//Print out a title banner
System.out.printf( "*********************************" );
System.out.printf( "Payroll Program Part 2" );
System.out.printf( "********************************\n\n" );
//Input the name of the employee
System.out.printf( "Please enter the employee's name ('stop' to quit): " );
employeeName = input.nextLine(); // Read a line of text
if ( employeeName.equalsIgnoreCase( "stop" ) )
{
break; //Break the main while loop
}// End if
// prompt and input hours worked
System.out.println("Please enter hours worked: " );
Double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line
// prompt and input pay rate
System.out.println( "Please enter pay rate: " );
Double payRate = input.nextDouble();// read a line of text
System.out.println(); // outputs a blank line
double weeklyPay = hoursWorked * payRate; // multiply numbers
System.out.printf( "Weekly pay is $%.2f", weeklyPay ); // display product
} // end method main
} // end class PayrollPartTwo
//Clean the input buffer
cleanInputBuffer = input.nextLine(); // Read a line of text to clean the input buffer
} // End while
This post has been edited by alcdotcom: 13 Jul, 2007 - 02:23 AM