Results 1 to 6 of 6

Thread: tlouvierre

  1. #1
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default tlouvierre

    // Payroll Program Part 2
    // Author: Tiffany D. Louvierre-Ramirez
    // April 30, 2009


    import java.util.Scanner; // program uses class Scanner

    public class Payroll Program Part 2
    {
    // main method begins execution of java application
    public static void main( String args[] )
    {
    System.out.println( "Welcome to the Payroll Program Calculator " );


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

    // 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 terminate 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
    {
    System.out.println( "Program Terminated" );
    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 for this iteration

    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( "Good-Bye" );
    System.out.println(); // outputs a blank line

    } // end method main

    } // end class Payroll1


    E:\IT 215 Java Programming\Payroll Program Part 2.java:7: class, interface, or enum expected
    {
    ^

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    9

    Default

    Don't give the classname with space.Please go thru sun site for declarations and code code conventions.
    Change the classname as "PayrollProgramPart2" and compile.

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    10

    Default

    filename and public class name need to be same

    and plz use meaningful title
    Last edited by mtyoung; 04-30-2009 at 12:57 PM.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    11

    Default

    Java Code:
    public class Payroll Program Part 2
    {
    The name of the class can't contain spaces. If you eant to use the above, it should be:
    Java Code:
    public class PayrollProgramPart2
    {
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default Using Spaces

    Quote Originally Posted by tlouvierre View Post
    // Payroll Program Part 2
    // Author: Tiffany D. Louvierre-Ramirez
    // April 30, 2009


    import java.util.Scanner; // program uses class Scanner

    public class Payroll Program Part 2
    {
    // main method begins execution of java application
    public static void main( String args[] )
    {
    System.out.println( "Welcome to the Payroll Program Calculator " );


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

    // 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 terminate 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
    {
    System.out.println( "Program Terminated" );
    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 for this iteration

    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( "Good-Bye" );
    System.out.println(); // outputs a blank line

    } // end method main

    } // end class Payroll1


    E:\IT 215 Java Programming\Payroll Program Part 2.java:7: class, interface, or enum expected
    {
    ^
    Thank you I will try and take this into consideration and I will let you know if it works. Thank you again. P.S. I have made this mistake before.

  6. #6
    tlouvierre is offline Member
    Join Date
    Apr 2009
    Location
    I live Stafford Texas right outside of Houston.
    Posts
    78
    Rep Power
    0

    Default

    Its a success. It compiles. Thank you. I actually lost the file and found it on your website. So thanks alot. Bye.

Posting Permissions

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