Here we go again...
My next assignment is the following:
Modify the Payroll Program so that it 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. Make sure the program maintains all the functionality required in previous assignments and your source code is readable and well documented. Use feedback you have received from the instructor to make any needed modifications.
Where do I begin? I have been searching my textbook for hours. I know once I get started I can figure it out, but I am lost.
Here is my payroll application, thus far:
[HTML]// Payroll3.java
// Payroll program that displays the weekly pay of employee.
import java.util.Scanner; // program uses class Scanner // Author: Nicki
public class Payroll3
{
// main method begins execution of Java application
public static void main( String args[] )
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
String name;
double rate;
double hours;
double weeklyPay;
// prompt for and input employee name
System.out.printf( "Enter the employee name:" );
name = input.next();
while (!name.equalsIgnoreCase("stop"))
{
// Hourly Rate input
System.out.printf( "Enter the employee's hourly rate in dollars:\n" );
rate = input.nextDouble( );
while ( rate < 0 )
{
System.out.printf( "Please enter a positive value:" );
rate = input.nextDouble( );
} // end while loop (pay rate)
// Hours Worked input
System.out.printf( "Enter the number of hours worked:\n" );
hours = input.nextDouble( );
while ( hours < 0 )
{
System.out.printf( "Please enter a positive value:" );
hours = input.nextDouble( );
} // end while loop (hours worked)
weeklyPay = rate * hours;
// Output the result
System.out.print(name + " earned ");
System.out.printf( " $%.2f", weeklyPay );
// prompt for and input employee name
System.out.printf( "Enter the employee name:" );
name = input.next( );
} // end while loop
} // end method main
} // end class Payroll3[/HTML]