Results 1 to 6 of 6
  1. #1
    cserenop51 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default Java Programming in Netbeans

    import java.util.Scanner; // program uses class Scanner
    public class NewClass5 {

    /**
    * @param args the command line arguments
    */
    // main method begins execution of java application
    public static void main( String args[] )
    {
    System.out.println( "Welcome to the Payroll Program " );


    boolean stop = false; // This flag will control whether we exit the loop

    // Loop until user types "stop" as the employee name:
    while (!stop)
    {
    // create scanner to obtain input from command window
    Scanner input = new Scanner ( System.in );


    System.out.println(); // outputs a blank line
    System.out.print( "Please enter the employee name or stop to end program: " );
    // prompt for and input employee name
    String empName = input.nextLine(); // read employee name


    if ( empName.equals("stop")) // Check whether user indicated to stop program
    {
    stop = true;
    }
    else
    {
    // User did not indicate to stop, so continue reading info for this iteration:
    float hourlyRate; // hourly rate
    float hoursWorked; // hours worked
    float weeklyPay; // Weekly Pay for employee

    System.out.print( "Enter hourly rate: " ); // prompt for hourly rate
    hourlyRate = input.nextFloat(); // read hourly rate


    while (hourlyRate <= 0) // prompt until a positive value is entered
    {
    System.out.print( "Hourly rate must be a positive value. " +
    "Please enter the hourly rate again: " ); // prompt for positive value for hourly rate
    hourlyRate = input.nextFloat(); // read hourly rate again
    }

    System.out.print( "Enter hours worked: " ); // prompt for # of hours
    hoursWorked = input.nextFloat(); // read # of hours


    while (hoursWorked <= 0) // prompt until a positive value is entered
    {
    System.out.print( "Hours worked must be a positive value. " +
    "Please enter the hours worked again: " ); // prompt for positive value for hours worked
    hoursWorked = input.nextFloat(); // read hours worked again
    }

    // Move on to calculate Weekly Pay.

    weeklyPay = (float) hourlyRate * hoursWorked; // multiply the hourly rate by the hours worked

    // Display output

    System.out.println(); // outputs a blank line
    System.out.print( empName ); // display employee name
    System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay); // display weekly pay
    System.out.println(); // outputs a blank line

    }
    }

    // Display ending message:
    System.out.println( "Program ended" );
    System.out.println(); // outputs a blank line

    } // end method main

    } // end class Payroll1


    Above is my payroll program and works to this point. My next step is

    create a class to store and retrieve the information within the program.

    I am lost and could use some pointers without actually doing the work.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Are you worrying about that how to create a class in NetBeans? Can you explain your question much clearly.

  3. #3
    cserenop51 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    I need to 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. then I need to use a constructor to initialize the
    employee information, and a method within that class to calculate the weekly pay.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    So where are you stuck with? Are you asking to write this code. First of all you have to make an attempt first. Then ask questions here lol. Start work on step-by-step.

  5. #5
    Nakira is offline Member
    Join Date
    Oct 2008
    Location
    Aberystwyth
    Posts
    55
    Rep Power
    0

    Default

    If you get stuck try breaking your code up into smaller segments. It is an OO Language. lol.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Java Programming Tutorial
    By levent in forum Java Tutorial
    Replies: 1
    Last Post: 07-04-2008, 08:15 AM
  2. Java networking programming (II)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-27-2007, 06:19 PM
  3. Java networking programming (I)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-24-2007, 07:21 PM
  4. Java Applet 3D programming
    By ramk in forum Java Applets
    Replies: 0
    Last Post: 11-28-2007, 10:36 PM
  5. Java Programming
    By JavaForums in forum Java Tutorial
    Replies: 0
    Last Post: 07-28-2007, 11:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •