Another Java question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NickiWood
    New Member
    • Jun 2008
    • 3

    Another Java question

    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.Scann er; // 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.prin tf( "Enter the employee name:" );
    name = input.next();

    while (!name.equalsIg noreCase("stop" ))
    {

    // Hourly Rate input
    System.out.prin tf( "Enter the employee's hourly rate in dollars:\n" );
    rate = input.nextDoubl e( );

    while ( rate < 0 )
    {
    System.out.prin tf( "Please enter a positive value:" );
    rate = input.nextDoubl e( );
    } // end while loop (pay rate)

    // Hours Worked input
    System.out.prin tf( "Enter the number of hours worked:\n" );
    hours = input.nextDoubl e( );

    while ( hours < 0 )
    {
    System.out.prin tf( "Please enter a positive value:" );
    hours = input.nextDoubl e( );
    } // end while loop (hours worked)

    weeklyPay = rate * hours;

    // Output the result
    System.out.prin t(name + " earned ");
    System.out.prin tf( " $%.2f", weeklyPay );


    // prompt for and input employee name
    System.out.prin tf( "Enter the employee name:" );
    name = input.next( );

    } // end while loop

    } // end method main

    } // end class Payroll3[/HTML]
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by NickiWood
    ....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. ..
    Your starting point is creating the Employee class.

    Comment

    • RedSon
      Recognized Expert Expert
      • Jan 2007
      • 4980

      #3
      Next time please provide a better title for your question instead of "Another Java Question"

      Comment

      Working...