• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

illegal start of expression

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I seem to be getting this error message now after i figured out why it wasnt running.Any ideas or suggestions on how to correct this?

C:\jdk1.5.0_14\bin>javac Payroll.java
Payroll.java:51: illegal start of expression
public void static main(String[] args) {}
^
1 error

import java.util.Scanner;


public class Payroll {

public Payroll() {

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




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


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

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);

}

public void static main(String[] args) {}
new Payroll();

;
} // end method main


} // end class Payroll
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check your braces.... When you get to this line...



You are still defining your constructor. You are not allowed to define a method within a constructor.

Henry
 
Aretha Clark
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you dont mind can you explain this a lil further im very new to this and atm this one project has me pulling out










import java.util.Scanner;


public class Payroll {

public Payroll() {

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




// prompt for and input employee name
System.out.println( "Please enter the employee name:" );
String employeeName = input.nextLine(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hourly wage
System.out.println( "Please enter the employee hourly wage:" );
double hourlyWage = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line

// prompt for and input employee hours worked
System.out.println( "Please enter the employee hours worked:" );
double hoursWorked = input.nextDouble(); // read a line of text
System.out.println(); // outputs a blank line


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

System.out.println("Employee Name: " + employeeName);
System.out.println("Hourly Wage: " + hourlyWage);
System.out.println("Hours Worked: " + hourlyWage);



public void static main(String[] args){)
new Payroll();



// end method main


// end class Payroll
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Braces must match. If you take your code and indent it according to braces, you will notice that what you mark as the end of main, is really the end of the constructor.

Henry

 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, the main method is defined within the constructor. The "new Payroll()" code which is probably supposed to be within the main() method, is actually not. It is also defined within the constructor -- after the main() method.


This indentation is probably *not* what you wanted. However, based on the braces, this is what the compiler interprets.

Henry
[ June 10, 2008: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Aretha,

You have made couple of mistakes.

1) Signature of main() method.

2) Braces are at improper location as henry pointed.
3) you are creating an object of Payroll class at improper place.

Always remember to indent your code, that can uncover many errors and enclose your code with CODE TAG so that other ranchers can understand your code hence the problem very easily.

Here is your modified code.Of course using CODE tag.

[ June 10, 2008: Message edited by: Vishal Pandya ]
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And yes, you are printing 'hourlyWage' in case of 'hours worked'.
 
Aretha Clark
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much its almost sickening that the misplacement of brackets can turn into a nightmare
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic