Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 118,887 Java Programmers for FREE! Ask your question and get quick answers from experts. There are 2,081 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



class, interface, or enum expected

 
Reply to this topicStart new topic

class, interface, or enum expected

sistanettie
post 1 Jul, 2008 - 02:02 PM
Post #1


New D.I.C Head

*
Joined: 1 Jul, 2008
Posts: 10

I keep getting this message for java:76. Here is my entire code.


java

//Annette Turner
//Payroll2.java
//Program that displays employee pay
import java.util.Scanner;//program uses class Scanner

public class Payroll2
{
// main method begins execution of java application

public static void main (String args [] )
{
string employeename;//name of employees
double hourlypayrate;//employee's hourly rate
double hoursworked;// employee's weely work hours
double weeklypay;// employee's 40 hour pay

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

//prompt for employeename
System.out.print(" Enter employeename: ");
employeename= input.next ();

//while statement
while( employeename.equalsIgnoreCase("stop"))
{

//prompt for and input hourlypayrate
System.out.println(" Enter hourlypayrate: ");
hourlypayrate= input.nextDouble ();//obtain user input

//while statment
while (payrate < 0);
{

System.out.print (" Please enter postive amount: ");
hourlypayrate= input.nextDouble ();

}//End while loop (" hourlypayrate");

//prompt for and input hoursworked
System.out.println(" Enter hoursworked: ");
hoursworked= input.nextDouble ();//obtain user input

//while statement
while(hoursworked < 0);
{
System.out.print (" Please enter postive amount: ");
hoursworked= input.nextDouble ();

}//End while loop (" hoursworked ");

System.out.print (" Enter the employeename: " );
employeename= input.next ();


//calculate weeklypay
weeklypay= hourlypayrate * hoursworked;

//display employeename and weeklypay
System.out.printf(" weeklypay for %,is $%.2f/n",employeeName,weeklypay);

System.out.println(); // output a blank line

System.out.print(" Please enter name(Input 'Stop' when finished)\n\n ");
name= input.nextline ();

}

}// End whileloop


} // End main method


} // End class Payroll2


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM

Go to the top of the page


Martyr2
post 1 Jul, 2008 - 02:36 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 4,669



Thanked 125 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


You have a curly brace mismatch. The one where you claim is the end of the while loop is actually the end of the main method.

This makes the last curly brace at the end that closes the class an extra closing brace. So delete the last one and rename your comments and you will be all set.

That or you accidentally closed a while loop prematurely. Either way you have one too many closing curly braces.

Hope this helps! smile.gif
User is offlineProfile CardPM

Go to the top of the page

sistanettie
post 1 Jul, 2008 - 03:14 PM
Post #3


New D.I.C Head

*
Joined: 1 Jul, 2008
Posts: 10

Hi Marty2
When I remove the curly brace at the end of the code it gave me a message reached end of file while parsing
User is offlineProfile CardPM

Go to the top of the page

RoboAlex
post 2 Jul, 2008 - 10:44 PM
Post #4


New D.I.C Head

*
Joined: 26 Jun, 2008
Posts: 39



Thanked 3 times
My Contributions


This code is riddled with problems.

For starters, half of your while() loops have semicolons after them!
while (payrate < 0); for example

next, you declare string employeename with string in lowercase, it should be uppercase. Also, you later refer to employeeName and name, neither of which (Java is case sensitive!)

you also refer to a nonexistent payrate variable, which I assume is hourlyPayRate

you call scanner.nextline(), it should be nextLine()

your while loop while(employeeName.equalsIgnoreCase("stop")) is, I assume, supposed to keep going until the employeeName is stop, in which case you want to add == false. So it keeps going while it isn't stop.

you prompt for employeename 3 times!

your System.printf() statement is broken.

also, you have an extra curly brace at the end.

Here's good practice, always name variables (as well as methods) lowercase, with words separated by capitalization. employeeName for example, or hourlyPayRate, having a standard keeps you from messing up capitalization.

I refactored the code and corrected some things, here it is:

CODE

//Annette Turner
//Payroll2.java
//Program that displays employee pay
import java.util.Scanner;//program uses class Scanner

public class Payroll2
{
    // main method begins execution of java application

    public static void main(String args[])
    {
        String employeeName;// name of employees
        double hourlyPayRate;// employee's hourly rate
        double hoursWorked;// employee's weely work hours
        double weeklyPay;// employee's 40 hour pay

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

        // while statement
        while(employeeName.equalsIgnoreCase("stop") == false)
        {

            // prompt for employeeName
            System.out.print(" Please enter name(Input 'Stop' when finished)");
            employeeName= input.next();

            // prompt for and input hourlypayrate
            System.out.print(" Enter hourlypayrate: ");
            hourlyPayRate= input.nextDouble();// obtain user input

            // while statment
            while(hourlyPayRate < 0)
            {

                System.out.print(" Please enter postive amount: ");
                hourlyPayRate= input.nextDouble();

            }// End while loop (" hourlypayrate");

            // prompt for and input hoursworked
            System.out.print(" Enter hoursworked: ");
            hoursWorked= input.nextDouble();// obtain user input

            // while statement
            while(hoursWorked < 0)
            {
                System.out.print(" Please enter postive amount: ");
                hoursWorked= input.nextDouble();

            }// End while loop (" hoursworked ");

            // calculate weeklypay
            weeklyPay= hourlyPayRate * hoursWorked;

            // display employeename and weeklypay
            System.out.println("weeklypay for " + employeeName + " is " + weeklyPay + "\n");

        }// End whileloop


    } // End main method


} // End class Payroll2
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/13/08 03:16AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month