8 Replies - 461 Views - Last Post: 21 October 2012 - 08:31 AM Rate Topic: -----

#1 BeBe922  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-September 12

Identifier Error

Posted 19 October 2012 - 12:03 AM

I would appreciate if someone would review my code. I understand what an identifier does, but I have reviewed the problem lines several times and cannot find the errors. I have looked for misspelled words, curly braces, and semi-colons errors. I think I need a fresh pair of eyes. All errors are stating identifier error. The errors are showing in the class for EmployeePayInfo. Lines 101,102,103,107,110,111,112.

import java.util.Scanner;													//program will use class scanner to obtain user input
 import java.text.NumberFormat;												//program will use class number format to format integer output
 import java.util.Locale;													//program will use U S currency
 
//PayrollProgramPartIII class starts
 public class PayrollProgramPartIII
 {
	//main method begins to execute Java application
	public static void main(String args[])
	{
		//variable specifications
		String EmployeeName;															//placeholder for employee name
		float HourlyRate;																//placeholder for hourly rate
		float HoursWorked;																//placeholder for hours worked
		float WeeklyPay;																//placeholder for total weekly pay[results of hourly rate times total hours worked for week]
		
		//create scanner to obtain input from keyboard
		Scanner input = new Scanner(System.in);
		
		//set currency to U S Dollars[$]
		NumberFormat uscurrency = NumberFormat.getCurrencyInstance(Locale.US);
		
		//display welcome message
		System.out.println();															//display empty line
		System.out.println("WELCOME TO PAYROLL PROGRAM PART III !!!");					//display welcome message
		System.out.println();															//display empty line
		
		//continous loop --> till ("stop") is entered for EmployeeName
		  while(true)
		  {
		//display empty line
		System.out.println();
		
		//prompt for employee name
		System.out.print("Enter Employee Name or Stop to EXIT Program):");				//prompt message
		EmployeeName = input.nextLine();												//read employee name
		
		//verify if user entered "stop" to end program
		if ( EmployeeName.equalsIgnoreCase("stop") )
	{
		break;																			//break the inifinite while loop
	}
	
	do
	{
	
		//prompt for employee hourly rate
		System.out.print("Enter Hourly Rate:    ");										//prompt message
		HourlyRate = input.nextFloat();													//read employee hourly rate
		if (HourlyRate < 0)
		{
			System.out.println("Enter Positive Amount Only!!!");						//display error message
		}
	} while(HourlyRate < 0);															//end while statement
	
	do
	{
		//prompt for total hours worked
		System.out.print("Enter Hours Worked:   ");										//primpt message
		HoursWorked = input.nextFloat();												//read total hours employee worked
		if (HoursWorked < 0)
		{
			System.out.println("Enter Positive Amount Only!!!");						//display error message
		}
	} while (HoursWorked < 0);															//end while statement
	
	//create new employee object called "emp"
	{
		EmployeeName emp = new Name();
	}
	
		//dispaly results
	System.out.println();																//display empty line
	System.out.println("EMPLOYEE NAME: " + emp.getEmployeeName());
	System.out.println("EMPLOYEE WEEKLY PAY:  "  + uscurrency.format(WeeklyPay));
	
	input.nextLine();															//this is required to go to next line --> input.nextDouble() doesn't do this, therefore must force 
		}//end while statement
		
	//display exit message
	System.out.println();														//display empty line
	System.out.print("EXITING PAYROLL PROGRAM PART III !!!!");					//display exit message
	System.out.println();														//display empty line
	}//end method main
	
}//PayrollProgramPartIII class ends



//Employee Pay Info Class
public class EmployeePayInfo 
{
	private String EmployeeName;																							//placeholder for employee name
	private float HourlyRate;																								//placeholder for hourly rate
	private float HoursWorked;																								//placeholder for total hours worked
	
	
	//constructor without parameters
	public class EmployeeName
	{
	setEmployeeName = "";																								//set employee name as unknown
	setHourlyRate = 0;																										//set hourly rate as zero
	setHoursWorked = 0;																										//set total hours worked as zero
	}
	
	//constructors which contains employee name, hourly rate, and total hours worked
	public class EmployeePayInfo( String EmployeeNameIn, float HourlyRateIn, float HoursWorkedIn );
	{
		//request three to constructor
		EmployeeName = EmployeeNameIn;																						//request employee name
		HourlyRate = HourlyRateIn;																							//request hourly rate
		HoursWorked = HoursWorkedIn;																						//request hours worked
	} //end requesting objects
		
	public void setEmployeeName(String EmployeeName){									
		this.EmployeeName = EmployeeName;																				//assign employee name
	}
	
	public String getEmployeeName(){
		return EmployeeName;																								//return employee name
	}
	
	public void setHourlyRate(float HourlyRate){
		this.HourlyRate = HourlyRate;																						//assign hourly rate
	}
	
	public float getHourlyRate(){
		return HourlyRate;																									//return hourly rate
	}
	
	public void setHoursWorked(){
		this.HoursWorked = HoursWorked;																						//assign total hours worked
	}
	
	public float getHoursWorked(){
		return HoursWorked;																									//return total hours worked
	}
	
	public float getWeeklyPay(){
		return HourlyRate * HoursWorked;																					//calculate weekly pay
	}
}// EmployeePayInfo class ends 
}//PayrollProgramPartII class ends


Is This A Good Question/Topic? 0
  • +

Replies To: Identifier Error

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Identifier Error

Posted 19 October 2012 - 12:16 AM

It is expecting some value and you need to give that value in the same line.

For eg.

 EmployeeName = 
EmployeeNameIn;



should be

 EmployeeName = EmployeeNameIn;



Similarly for your other lines as well.That should resolve your problem. :)

Also,I don't understand why you do this.

 float
 HourlyRate; 



It should be

 float HourlyRate; 



Do similarly for other variables too :)

regards,
Raghav

This post has been edited by raghav.naganathan: 19 October 2012 - 12:17 AM

Was This Post Helpful? -2
  • +
  • -

#3 karabasf  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 202
  • View blog
  • Posts: 417
  • Joined: 29-August 10

Re: Identifier Error

Posted 19 October 2012 - 01:06 AM

View Postraghav.naganathan, on 19 October 2012 - 09:16 AM, said:

It is expecting some value and you need to give that value in the same line.


[The rest of the post]


This is not true and furthermore, the return is caused by the forum code format. The error states that it is expecting an identifier, meaning that it expects an Objecttype for the parameter and not a value. (As that would result in an unassigned variable error, if the parameter needs to be evaluated or whatsoever)

Anyways, consider the lines of your error:
//constructor without parameters
public class EmployeeName
{
	setEmployeeName = "";	//set employee name as unknown
	setHourlyRate = 0;		//set hourly rate as zero
	setHoursWorked = 0;	//set total hours worked as zero
}



Your constructor is wrong here. First of all it should be called EmployeePayInfo, because that's the name of your class. Second, the parameters of the constructor are wrong. You don't have a declared parameter called setEmployeeName, setHourlyRate, setHoursWorked. You either meant to call the method called setEmployeeName (etc) or you want to set the parameters directly:

//constructor without parameters
public EmployeePayInfo() //This is how you should declare a parameterless constructor
{
	setEmployeeName("");	//set employee name as unknown
	setHourlyRate(0.0);		//set hourly rate as zero
	setHoursWorked(0);	//set total hours worked as zero
}

// Which is equally valid to:
public EmployeePayInfo() // You shouldn't put a semicolon behind a declaration of a constructor.
{
	//Set the parameters of the object
	EmployeeName = "";		//set employee name
	HourlyRate = 0.0;			//set hourly rate
	HoursWorked = 0;			//set hours worked
} //end requesting objects


This post has been edited by karabasf: 19 October 2012 - 06:39 AM

Was This Post Helpful? 2
  • +
  • -

#4 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Identifier Error

Posted 19 October 2012 - 01:23 AM

I am sorry karabasf, and thanks for that information. I have always been taught to initialize the variables in the same line. That is the reason why I thought that could be the reason for the error.

Thank you for making me learn something new today :)

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#5 BeBe922  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-September 12

Re: Identifier Error

Posted 19 October 2012 - 02:42 AM

View Postkarabasf, on 19 October 2012 - 01:06 AM, said:

View Postraghav.naganathan, on 19 October 2012 - 09:16 AM, said:

It is expecting some value and you need to give that value in the same line.


[The rest of the post]


This is not true and furthermore, the return is caused by the forum code format. The error states that it is expecting an identifier, meaning that it expects an Objecttype for the parameter and not a value. (As that would result in an unassigned variable error, if the parameter needs to be evaluated or whatsoever)

Anyways, consider the lines of your error:
//constructor without parameters
public class EmployeeName
{
	setEmployeeName = "";	//set employee name as unknown
	setHourlyRate = 0;		//set hourly rate as zero
	setHoursWorked = 0;	//set total hours worked as zero
}



Your constructor is wrong here. First of all it should be called EmployeePayInfo, because that's the name of your class. Second, the parameters of the constructor are wrong. You don't have a declared parameter called setEmployeeName, setHourlyRate, setHoursWorked. You either meant to call the method called setEmployeeName (etc) or you want to set the parameters directly:

//constructor without parameters
public EmployeePayInfo() //This is how you should declare a parameterless constructor
{
	setEmployeeName("");	//set employee name as unknown
	setHourlyRate(0.0);		//set hourly rate as zero
	setHoursWorked(0);	//set total hours worked as zero
}

// Which is equally valid to:
public EmployeePayInfo( String EmployeeNameIn, float HourlyRateIn, float HoursWorkedIn ) // You shouldn't put a semicolon behind a declaration of a constructor.
{
	//Set the parameters of the object
	EmployeeName = "";		//set employee name
	HourlyRate = 0.0;			//set hourly rate
	HoursWorked = 0;			//set hours worked
} //end requesting objects


Was This Post Helpful? 0
  • +
  • -

#6 BeBe922  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-September 12

Re: Identifier Error

Posted 19 October 2012 - 02:54 AM

Thank You so MUCH!! This really help and I do appreciate the help. Now I only have one error the very last line. It is stating class, interface, or enum is expected. I a a newbie. Some days I think I have a good understanding and then there are days like today. I did the first two part perfect and this part just seems so difficult. I truly thankful for this site and people like you guys.
Was This Post Helpful? 0
  • +
  • -

#7 karabasf  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 202
  • View blog
  • Posts: 417
  • Joined: 29-August 10

Re: Identifier Error

Posted 19 October 2012 - 04:01 AM

Assuming that the code did not change, except for the constructs, you have (as far as I can see) a curly brace too much ;)
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

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

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Identifier Error

Posted 19 October 2012 - 07:41 PM

View Postraghav.naganathan, on 19 October 2012 - 03:16 AM, said:

It is expecting some value and you need to give that value in the same line.

For eg.

 EmployeeName = 
EmployeeNameIn;



should be

 EmployeeName = EmployeeNameIn;



Male cattle excrement !!!

A Java stement start on a line and continue until the ;
so this is valid code:

int

a

=


b


+


100



;


Was This Post Helpful? 1
  • +
  • -

#9 BeBe922  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-September 12

Re: Identifier Error

Posted 21 October 2012 - 08:31 AM

Thank You very much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1