Results 1 to 14 of 14
  1. #1
    joshwey is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Exclamation payroll program 2

    having problems with my code i can not get it to run it says I have 2 errors but the errors don't make any sense. Does anyone know what I'm doing wrong.


    Heres my code.

    /*
    *
    * Payroll Program - PayrollProgram Class
    * Axia College - University of Phoenix
    * IT 215 - Java Programming
    *
    */


    import java.util.Scanner; // Program uses class Scanner to accept user input
    import java.text.NumberFormat; // Program Uses Class NumberFormat to format number output
    import java.util.Locale; // Program Needs to Use U.S. Currency



    public class PayrollProgram
    {

    public static void main(String[] args)
    {


    // create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );

    // Set Currency to U.S. Dollars
    NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);

    // Variable Specifications
    String employeeName; // Placeholder for employee name
    float hoursWorked; // Number of hours worked in a week
    float hourlyRate; // Employee's hourly rate
    float weeklyPay; // Weekly pay as product of hours worked and the hourly rate

    // Show Program Welcome Message
    System.out.println( ); // Show an Empty Line
    System.out.println( "Welcome to the Payroll Program!!!"); // Show Welcome Message
    System.out.println( );


    while(true) // continuous loop --> loops until "stop" is entered as the employeeName
    {


    // Show an Empty Line
    System.out.println( );

    // Prompt for Employee Name
    System.out.print( "Enter employee name (or STOP to exit the program): " ); // prompt message
    employeeName = input.nextLine(); // read the employee's name

    // Check to See if the User Entered "stop" to End the Program
    if ( employeeName.equalsIgnoreCase("stop") )
    {
    break; // Break Out of While Loop



    do
    {


    // Prompt for Employee's Hourly Pay Rate
    System.out.print( "Enter hourly rate: " ); // prompt message
    hourlyRate = input.nextFloat(); // read the employee's hourly pay rate

    if (hourlyRate < 0)
    {

    System.out.println( "ERROR: The hourly rate must be a positive number." ); // show error message

    }


    } while ( hourlyRate < 0 ); // end do while statement


    do
    {


    // Prompt for Number of Hours Worked
    System.out.print( "Enter hours worked: " ); // prompt message
    hoursWorked = input.nextFloat(); // read number of hours worked in a week

    if (hoursWorked < 0)
    {

    System.out.println( "ERROR: The number of hours worked must be a positive number." ); // show error message

    }


    } while ( hoursWorked < 0 ); // end do while statement


    // Calculate Employee's Weekly Pay
    weeklyPay = hourlyRate * hoursWorked;

    // Output program results to the display
    System.out.println( ); // Show an Empty Line
    System.out.println( "Employee Name: " + employeeName);
    System.out.println( "Employee's Weekly Pay = " + currency.format(weeklyPay) );



    input.nextLine(); // Need this to remove carriage return from input queue

    } // end while statement

    // Show Program Exit Message
    System.out.println( ); // Show an Empty Line
    System.out.println( "Now exiting the Payroll Program."); // Show Exit Message
    System.out.println( ); // Show an Empty Line


    } //end While statement

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Please copy and paste your error messages for us to see. We can't read minds, so any help you can give us to help you will be nice.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,862
    Rep Power
    19

    Default

    Please use code tags when posting code.
    Java Code:
    like so
    ...and your errors are (in full, indicating the lines they occur on)?
    You can't expect people to copy and paste the code and try and compile it themselves...

  4. #4
    joshwey is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    sorry about that i forgot to put them in


    C:\Users\Josh\Documents\NetBeansProjects\Payroll Program Part 2\src\PayrollProgram.java:118: '}' expected
    1 error
    C:\Users\Josh\Documents\NetBeansProjects\Payroll Program Part 2\nbproject\build-impl.xml:363: The following error occurred while executing this line:
    C:\Users\Josh\Documents\NetBeansProjects\Payroll Program Part 2\nbproject\build-impl.xml:168: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)

    thanks again for the help

  5. #5
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Well you're missing a } somewhere. Whats line 118?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,862
    Rep Power
    19

    Default

    You need to show us where these lines are.
    As I said, you can't expect us to copy and paste this code into an IDE.

  7. #7
    joshwey is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    well I'm new to this form and still trying to figure it out so if you could help because i do not know how to tag my code to make it easier for you to help me

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,862
    Rep Power
    19

    Default

    If you quote my earlier post you'll see the code tags.

  9. #9
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    [code][/code] Is the tags you want to use. Putting your code in between them.

    Also, if you tell us what line 118 is we might be able to help you out a little bit more.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  10. #10
    joshwey is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default here you go

    Java Code:
    import java.util.Scanner;           	// Program uses class Scanner to accept user input
    import java.text.NumberFormat;		// Program Uses Class NumberFormat to format number output
    import java.util.Locale;            	// Program Needs to Use U.S. Currency
    
    
    
    public class PayrollProgram 
    {
    
    	public static void main(String[] args) 
    	{
    
    
    		// create Scanner to obtain input from command window
    Scanner input = new Scanner( System.in );
    
    // Set Currency to U.S. Dollars
    NumberFormat currency = NumberFormat.getCurrencyInstance(Locale.US);
    
    // Variable Specifications
    String employeeName;			// Placeholder for employee name
    float hoursWorked;				// Number of hours worked in a week
    float hourlyRate; 				// Employee's hourly rate
    float weeklyPay;				// Weekly pay as product of hours worked and the hourly rate
    
    // Show Program Welcome Message
    System.out.println( );										// Show an Empty Line
    System.out.println( "Welcome to the Payroll Program!!!");	// Show Welcome Message
    System.out.println( );
    		
    		
            while(true)  // continuous loop --> loops until "stop" is entered as the employeeName
            {
    
    	        
    			// Show an Empty Line
    System.out.println( );
    
    // Prompt for Employee Name
    System.out.print( "Enter employee name (or STOP to exit the program): " ); 	// prompt message
    employeeName = input.nextLine(); 				// read the employee's name
    
    // Check to See if the User Entered "stop" to End the Program
    if ( employeeName.equalsIgnoreCase("stop") )
    {
        break;	// Break Out of While Loop
    	        
    
    
               [B][I][COLOR="DarkOrange"] do [/COLOR][/I][/B]
                {
    
    	            
    				// Prompt for Employee's Hourly Pay Rate
    System.out.print( "Enter hourly rate: " ); 		// prompt message
    hourlyRate = input.nextFloat(); 				// read the employee's hourly pay rate
    
    if (hourlyRate < 0)
    {
    
        System.out.println( "ERROR: The hourly rate must be a positive number." ); 		// show error message
    
    }
                    
    				
                } while ( hourlyRate < 0 ); // end do while statement
    
    	
                do
                {
    
    
    				// Prompt for Number of Hours Worked
    System.out.print( "Enter hours worked: " ); 		// prompt message
    hoursWorked = input.nextFloat(); 					// read number of hours worked in a week
    
    if (hoursWorked < 0)
    {
    
        System.out.println( "ERROR: The number of hours worked must be a positive number." ); 		// show error message
    
    }
    	                          
                    
                } while ( hoursWorked < 0 ); // end do while statement
    
    
    			// Calculate Employee's Weekly Pay
    weeklyPay = hourlyRate * hoursWorked;
    
    // Output program results to the display
    System.out.println( );		// Show an Empty Line
    System.out.println( "Employee Name: " + employeeName);
    System.out.println( "Employee's Weekly Pay = " + currency.format(weeklyPay) );
                
                
    
                input.nextLine(); // Need this to remove carriage return from input queue
    			
    }  	// end while statement
    
            // Show Program Exit Message
            System.out.println( );											// Show an Empty Line
            System.out.println( "Now exiting the Payroll Program.");		// Show Exit Message	
            System.out.println( );											// Show an Empty Line
    
    
            [COLOR="Red"][B]}[/B][/COLOR]
    Last edited by joshwey; 05-13-2011 at 08:21 AM.

  11. #11
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    The end brace has to have a / in front of code, [/code]

    Also, any visual indication of the error line is fine, bold it, italicize, color, etc.

  12. #12
    joshwey is offline Member
    Join Date
    May 2011
    Posts
    5
    Rep Power
    0

    Default

    line 59 is a do statement and it say's its not a reachable statement

    Line 117 is the last line of my code it does not make any sense because my teacher made the code and we piece it together, and he said there were no errors. It says reached end of
    file while parsing
    thanks

  13. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default

    Java Code:
    System.out.println( ); // Show an Empty Line
    System.out.println( "Now exiting the Payroll Program."); // Show Exit Message 
    System.out.println( ); // Show an Empty Line
    
    
    } // end of main method
    
     // no closing bracket for the class
    If this is you actuall code then you are missing a bracket at the end. Otherwise you have a mis-matched brackets somewhere else in your code. Don't make us go through your code line by line to find it. This is a job that you have to do.

  14. #14
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,862
    Rep Power
    19

    Default

    As for the do error:
    Java Code:
    if ( employeeName.equalsIgnoreCase("stop") )
    {
       [B] break;	// Break Out of While Loop[/B]
                do
    You will always exit the outer while loop before getting to the do command.

    So, if this is the code that was working for yout teacher, then you've copied it incorrectly somehow.

Similar Threads

  1. Payroll program
    By bigley04 in forum Eclipse
    Replies: 7
    Last Post: 12-06-2010, 04:57 PM
  2. payroll generation
    By kriti in forum New To Java
    Replies: 5
    Last Post: 06-02-2010, 03:21 PM
  3. Need help ASAP with Payroll Program Part 2
    By arrech326 in forum New To Java
    Replies: 10
    Last Post: 11-17-2009, 10:17 PM
  4. Payroll output thingy...
    By ShadowUndertow in forum NetBeans
    Replies: 3
    Last Post: 08-25-2009, 02:25 AM
  5. Payroll Program exits at wrong time
    By jsand2 in forum Java Applets
    Replies: 13
    Last Post: 01-26-2009, 03:10 AM

Tags for this Thread

Posting Permissions

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