Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Help Please!!!

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Help Please!!!

    Not sure what's missing or should be removed... and not sure if I used the code tags correctly. Thanks in advance for your help!!



    //Payroll2
    //Rachel Wells  IT215
    import java.util.Scanner;// program to use import scanner
     
    public class Payroll2
     
    {
     
    	//main method begins execution of java program execution
    	public static void main( String args[] )
     
    {
     
          System.out.println( "Welcome to the Payroll Program!" );
     
     
    	boolean stop = false; // 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 Employee's Name or stop to exit program: " );
          String empName = input.nextLine(); // employee name
     
          if ( empName.equals("stop"))
    {
          System.out.println( "Exiting Program" );
          stop = true;
          }//end if
     
          else
    {
          float hourlyRate; // hourly rate
     
          float hoursWorked; // hours worked
     
          float weeklyPay; // Weekly Pay for employee
     
          System.out.print( "Please enter hourly rate: " ); // prompt for hourly rate
     
          hourlyRate = input.nextFloat();
     
          while (hourlyRate <= 0) // prompt until positive value is entered
     
    {
          System.out.print( "Hourly rate must be a positive value. " +
     
          "Please enter the hourly rate again: " );
     
          hourlyRate = input.nextFloat(); // read hourly rate again
     
     
    }//end while
     
     
     
          System.out.print( "Please enter hours worked: " ); // prompt for hours worked
     
          hoursWorked = input.nextFloat();
     
     
          while (hoursWorked <= 0) // prompt until positive value is entered
     
    {
     
          System.out.print( "Hours worked must be a positive value. " +
     
          "Please re-enter hours worked: " ); // prompt for positive value
     
          hoursWorked = input.nextFloat(); //
     
          }//end while
     
     
    {     // Calculate Weekly Pay.
     
          weeklyPay = (float) hourlyRate * hoursWorked; // * sum
     
     
          // Display Output Results and sum
     
     
          System.out.print( empName ); // display employee name
     
          System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay); //display weeklypay
     
     
     
    // end method main
     
     
    // end class Payroll2
    Last edited by helloworld922; May 22nd, 2011 at 03:17 PM.

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Help Please!!!

    What specifically did you need help with? Does your code work as intended? If not, what is not working? Are you getting an exception or compile error? If so, please post the error message.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Help Please!!!

    Not sure what the bracket for this line is for

    { // Calculate Weekly Pay.


    Also, does your else

    {

    have a closing bracket to it

    Also, it appears you don't have closing brackets for either the main method or the program itself and you need those.

    Also, as it appears that empName is defined inside a while loop, instead of before it, it won't be able to recognize the variable as it has become a sort of local variable that goes away when the while loop exits (hence it won't be able to figure out what empName is when you print it out with that println at the end.).

  4. #4
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Please!!!

    @helloworld922:

    Thanks for your reply!!

    Here is what I get in the command screen:

    Microsoft Windows [Version 6.0.6002]
    Copyright (c) 2006 Microsoft Corporation. All rights reserved.

    C:\Users\Rachel>cd Desktop

    C:\Users\Rachel\Desktop>javac Payroll2.java
    Payroll2.java:91: reached end of file while parsing
    System.out.printf( "'s weekly pay is: $%,.2f\n", weeklyPay); //display wee
    klypay
    ^
    Payroll2.java:100: reached end of file while parsing

    ^
    2 errors

    C:\Users\Rachel\Desktop>

    I put it into Netbeans and it has a lot of errors. I'm not even sure where to begin.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help Please!!!

    @javapenguin:

    I was thinking that my brackets were out of whack and have attempted to fix them, but now I see that as you said, I will have to correct where empName is and see how that works.

    Thanks for your response!!!

  6. #6
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    471
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Help Please!!!

    A tip that may help with curly braces {} is to always type both when you start a code block, then you can just type the code between them. Using sensible indentation of the braces allows you to see more easily when they are missing.