6 Replies - 1686 Views - Last Post: 20 April 2009 - 04:20 PM Rate Topic: -----

#1 ludger  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-April 09

I am having trouble fixing illegal start of expression error messages

Post icon  Posted 18 April 2009 - 05:45 PM


/*	Name		Lungelo
	Date		24 October 2005
	Filename	Employee.java
*/

import java.io.*;

public class Employee
{
	public static void main(String[] args)
	{
		//Declare class variables
		String FirstName;
		String LastName;
		String Position;
		float Rate;
		float Hours;

		public Employee(f,l,p,r,h)
		{
			FirstName = f;
			LastName = l;
			Position = p;
			Rate = r;
			Hours = h;
		}


		public float Employee(float r, h)
		{
			//assign each of the identifiers to its corresponding variable
			Rate = r;
			Hours = h;

		}

		public String Employee(String l, String f, String p)
		{
			//assign each of the identifiers to its corresponding variable
			FirstName = l;
			LastName =;
			Position = p;
		}

		public String getFirstName()
		{
			System.out.println();
			System.out.println("Please enter your First Name");
			System.out.println();

			return l;
		}

		public String getLastName()
		{
			System.out.println();
			System.out.println("Please enter your Last Name");
			System.out.println();

			return f;

		}

		public String getPosition()
		{
			System.out.println();
			System.out.println("Please enter your Position in the company");
			System.out.println();

			return p;

		}

		public float getRate()
		{
			System.out.println();
			System.out.println("Please enter the rate amount");
			System.out.println();

			return r;
		}

		public float getHours()
		{
			System.out.println();
			System.out.println("Please enter the number of hours");
			System.out.println();
		}
			return h;

	}


}




Is This A Good Question/Topic? 0
  • +

Replies To: I am having trouble fixing illegal start of expression error messages

#2 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: I am having trouble fixing illegal start of expression error messages

Posted 18 April 2009 - 05:48 PM

Hi and welcome to DIC.
The introduce yourself forum is actually for introductions and greetings. could you please post this in the correct forum which canbe found on the left side of screen

thanks
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is online

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,858
  • Joined: 06-March 08

Re: I am having trouble fixing illegal start of expression error messages

Posted 18 April 2009 - 09:18 PM

	   public Employee(f,l,p,r,h)


You will have to declare what f,l,p,r,h are ? String, int, fload, double, other objects ? like in
	   public Employee(float f, int l, double p, String r, MacDonals h)



public float Employee(float r, h)

according to your previous mistake you probably meant

public float Employee(float r, float h)

	   public String getFirstName()
		{
			System.out.println();
			System.out.println("Please enter your First Name");
			System.out.println();

			return l;
		}



What is "l" ???

	   public String getLastName()
		{
			System.out.println();
			System.out.println("Please enter your Last Name");
			System.out.println();

			return f;

		}


What is f ???

Fix these and we'll see the others after :)
Was This Post Helpful? 0
  • +
  • -

#4 porky101  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 97
  • Joined: 23-September 08

Re: I am having trouble fixing illegal start of expression error messages

Posted 20 April 2009 - 03:13 PM

First you for got to declare the variables in the parameters of your methods. Do it like so:
public class Employee
{
	public static void main(String[] args)
	{
		//Declare class variables
		String FirstName;
		String LastName;
		String Position;
		float Rate;
		float Hours;

		public Employee(String f, String l, String p, float r, float h)
		{
			FirstName = f;
			LastName = l;
			Position = p;
			Rate = r;
			Hours = h;
		}



Also for the return statements you cannot return the variables that you stated in the constructor, that just takes the information from your object decleration and changes it to your varibales FirstName, LastName, Position, Rate, Hours. And being that you are returning System.out.println() make only one System.out.println() like so:

 public String getPosition()
		{
			String msg = "";
			msg = System.out.println("Please enter your Position in the company");
		   

			return msg;

		}



To show what you are returning make a new class all the way at the bottom with a public static void main(String[] args) method and display it by using: System.out.println(object.getPosition())

I believe you can also do it this way:

 public String getPosition()
		{
		  
			return System.out.println("Please enter your Position in the company");
	

		}



I think it only works in a toString() method though I am not certain. Just when displaying it in you public static void main(String[] args) method be sure to make it System.out.println(object.getPosition())


Hopefully, that was not to confusing and helped you out.

This post has been edited by porky101: 20 April 2009 - 03:14 PM

Was This Post Helpful? 0
  • +
  • -

#5 porky101  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 97
  • Joined: 23-September 08

Re: I am having trouble fixing illegal start of expression error messages

Posted 20 April 2009 - 03:23 PM

Just noticed something else wrong, when you declare your class variables it should not be under a method it should be under the class like so:
public class Employee
{
		//Declare class variables
		String FirstName;
		String LastName;
		String Position;
		float Rate;
		float Hours;



Was This Post Helpful? 0
  • +
  • -

#6 sudoNut  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 21
  • Joined: 19-April 09

Re: I am having trouble fixing illegal start of expression error messages

Posted 20 April 2009 - 03:53 PM

View Postporky101, on 20 Apr, 2009 - 02:23 PM, said:

Just noticed something else wrong, when you declare your class variables it should not be under a method it should be under the class like so:
public class Employee
{
		//Declare class variables
		String FirstName;
		String LastName;
		String Position;
		float Rate;
		float Hours;




Although not required it is good practice to set the visibility of your variable also i.e. using the public, private or protected keywords

e.g.


 private String firstName;




Also strongly recommend the Java tutorials at http://java.sun.com/...books/tutorial/
Was This Post Helpful? 0
  • +
  • -

#7 porky101  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 97
  • Joined: 23-September 08

Re: I am having trouble fixing illegal start of expression error messages

Posted 20 April 2009 - 04:20 PM

Yea lol, my comp sci teacher just gave us a lesson on that... should have put that in there to make him proud :)

Quote

Also strongly recommend the Java tutorials at http://java.sun.com/...books/tutorial/



Another good tutorial site is the one we use in my High School: http://chortle.ccsu....ava5/index.html

This post has been edited by porky101: 20 April 2009 - 04:22 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1