Welcome to Dream.In.Code
Become a Java Expert!

Join 150,421 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,107 people online right now. Registration is fast and FREE... Join Now!




Payroll Program Part 2

 
Reply to this topicStart new topic

Payroll Program Part 2, 1 error

scudmore
26 Mar, 2008 - 02:22 PM
Post #1

New D.I.C Head
*

Joined: 25 Mar, 2008
Posts: 2


My Contributions
I am new to this java. I have a code for Payroll Program Part 2. I cannot get it to compile, because there is one error in it that I cannot find. Can anyone help me out? Thank you.

CODE

//PayrollProgramPart2
import java.util.Scanner; // class Scanner

public class PayrollProgramPart2
{
    //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 employeeName; // input
        double hourlyRate; // input
        double hoursWorked; // input
        double sum; // weekly pay
        boolean end = false; // is the input name stop?
        while(end==false) // as long as end is false, proceed
        {
            hourlyRate = -1; // this way, both are initiated to be -1;
            hoursWorked = -1;
            System.out.print("Enter Name of Employee:");
            employeeName = input.nextLine();
            if(employeeName.toLowerCase()=="stop")
            end=true; // when the stop is detected, change the boolean, which will end the while loop while(hourlyRate<0) // since this was initiated to -1, it will loop until it gets a positive value
            {
                System.out.print("Enter a positive hourly rate:"); // prompt
                hourlyRate = input.nextDouble(); // input
                {
                    while(hourseWorked<0) // same as hourlyRate while loop
                {
                System.out.print("Enter a positive number of hours worked:"); // prompt
                hoursWorked = input.nextDouble(); // input
            }
            sum = hourlyRate * hoursWorked; // * numbers

            System.out.printf("The employee%s was paid $ %.2fthis week", employeeName, sum);

        } // end outer while

    } // end method main

} // end class PayrollProgramPart2

//Clean the input buffer
cleanInputBuffer=input.nextLine();//Read a line of text to clean the input buffer

} //End while


Here is the error:

C:\Users\scudmore\Desktop\IT 215\ASSIGNMENTS\PayrollProgramPart2.java:47: reached end of file while parsing
} //End while

1 error

Tool completed with exit code 1

This post has been edited by scudmore: 26 Mar, 2008 - 03:53 PM
User is offlineProfile CardPM
+Quote Post

Mr. X
RE: Payroll Program Part 2
26 Mar, 2008 - 07:23 PM
Post #2

New D.I.C Head
Group Icon

Joined: 19 Mar, 2008
Posts: 7


Dream Kudos: 50
My Contributions
Hello there. I tidied up a few things for you; here's the revised code.

CODE

//PayrollProgramPart2
import java.util.Scanner; // class Scanner

public class PayrollProgramPart2
{
    //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 cleanInputBuffer; //input
        String employeeName; // input
        double hourlyRate; // input
        double hoursWorked; // input
        double sum; // weekly pay
        boolean end = false; // is the input name stop?
        while (end == false) // as long as end is false, proceed
        {
            hourlyRate = -1; // this way, both are initiated to be -1;
            hoursWorked = -1;
            System.out.print("Enter Name of Employee:");
            employeeName = input.nextLine();
            if(employeeName.toLowerCase() == "stop")
                end = true; // when the stop is detected, change the boolean, which will end the while loop while(hourlyRate<0) // since this was initiated to -1, it will loop until it gets a positive value
            System.out.print("Enter a positive hourly rate:"); // prompt
            hourlyRate = input.nextDouble(); // input
            
            while (hoursWorked < 0) // same as hourlyRate while loop
            {
                System.out.print("Enter a positive number of hours worked:"); // prompt
                hoursWorked = input.nextDouble(); // input
            }
            sum = hourlyRate * hoursWorked; // * numbers

            System.out.printf("The employee %s was paid $ %.2f this week", employeeName, sum);
            //Clean the input buffer
        cleanInputBuffer = input.nextLine(); //Read a line of text to clean the input buffer

        } // end outer while

    } // end method main

} // end class PayrollProgramPart


Basically, you were missing one brace and the second while loop was going over its limits pretty much. I also fixed a small typo on the second loop "while (hourseWorked > 0)", so that should take care of that problem before it happens. smile.gif

I also had to declare cleanInputBuffer at the top as it was complaining about a "missing symbol" A.K.A. no variable declaration, so I fixed that up too.

Hope that helps.
User is offlineProfile CardPM
+Quote Post

scudmore
RE: Payroll Program Part 2
3 Apr, 2008 - 09:57 AM
Post #3

New D.I.C Head
*

Joined: 25 Mar, 2008
Posts: 2


My Contributions
Thank you so much for your help. It helped me out a great deal. This helped me figure out what I did wrong. Thanks again.
scudmore




QUOTE(Mr. X @ 26 Mar, 2008 - 08:23 PM) *

Hello there. I tidied up a few things for you; here's the revised code.

CODE

//PayrollProgramPart2
import java.util.Scanner; // class Scanner

public class PayrollProgramPart2
{
    //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 cleanInputBuffer; //input
        String employeeName; // input
        double hourlyRate; // input
        double hoursWorked; // input
        double sum; // weekly pay
        boolean end = false; // is the input name stop?
        while (end == false) // as long as end is false, proceed
        {
            hourlyRate = -1; // this way, both are initiated to be -1;
            hoursWorked = -1;
            System.out.print("Enter Name of Employee:");
            employeeName = input.nextLine();
            if(employeeName.toLowerCase() == "stop")
                end = true; // when the stop is detected, change the boolean, which will end the while loop while(hourlyRate<0) // since this was initiated to -1, it will loop until it gets a positive value
            System.out.print("Enter a positive hourly rate:"); // prompt
            hourlyRate = input.nextDouble(); // input
            
            while (hoursWorked < 0) // same as hourlyRate while loop
            {
                System.out.print("Enter a positive number of hours worked:"); // prompt
                hoursWorked = input.nextDouble(); // input
            }
            sum = hourlyRate * hoursWorked; // * numbers

            System.out.printf("The employee %s was paid $ %.2f this week", employeeName, sum);
            //Clean the input buffer
        cleanInputBuffer = input.nextLine(); //Read a line of text to clean the input buffer

        } // end outer while

    } // end method main

} // end class PayrollProgramPart


Basically, you were missing one brace and the second while loop was going over its limits pretty much. I also fixed a small typo on the second loop "while (hourseWorked > 0)", so that should take care of that problem before it happens. smile.gif

I also had to declare cleanInputBuffer at the top as it was complaining about a "missing symbol" A.K.A. no variable declaration, so I fixed that up too.

Hope that helps.


User is offlineProfile CardPM
+Quote Post

Locke37
RE: Payroll Program Part 2
3 Apr, 2008 - 02:00 PM
Post #4

Contributor of the Year
Group Icon

Joined: 20 Mar, 2008
Posts: 1,274



Thanked: 58 times
Dream Kudos: 325
My Contributions
One more problem...this may screw a few things up.

You can't use the "==" conditional operator with Strings.

You have to use this...

CODE
if (employeeName.toLowerCase().equals("stop"))


The .equals() method returns a true/false, based on the characters.

The "==" only works in some...rare cases.

If you're wondering where your error was, it is in your first while loop, where you input employeeName.

This post has been edited by Locke37: 3 Apr, 2008 - 02:06 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:22PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month