5 Replies - 1095 Views - Last Post: 05 September 2009 - 10:42 AM Rate Topic: -----

#1 trillian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-August 09

Need help with syntax errors, once again please

Post icon  Posted 05 September 2009 - 07:42 AM

I am getting the error '.cass' expected and ';' for Line 51 in Payroll3.java (I know you have seen this before, however the fixes suggested in previous posts, havn't been able to fix mine). ***All help/tips are appreciated***

Here is my code:

	/*
	 * Author: Jamie 
	 * Date Modified: 04-09-2009 11:06 PM
	 * Payroll3 file1 Payroll3.java
	 * Purpose: To calculate weekly salary, then display's the result.
	 * 
	 */
	import java.util.Scanner; //import Scanner Class for use

	public class Payroll3{
		public static void main(String[] args) 
		{
			Scanner input = new Scanner(System.in); //create Scanner Object
			
			String name = "";	 //declare variables
			double hourlyRate = 0;
			double hoursWorked = 0;
			double weeklyPay = 0;
			
			do
			{
			//prompt for user input and receive input
			System.out.println( "\nEnter the name of the employee or type 'stop' to quit: " ); 
			name = input.nextLine();
				
			System.out.println( "Enter the hourly pay rate: " );
				if( hourlyRate <= 0 ) 
				{
					System.out.println( "Positive Number Required"  );
					continue;
				}
			hourlyRate = input.nextDouble();
			
			System.out.println( "Enter the total number of hours worked for this week:  "  ); // prompt
				if( hoursWorked <= 0 ) 
				{		   
					System.out.print( "Positive Number Required " );
					continue;
				}
			hoursWorked = input.nextDouble(); // read second number
			
			//Create Employee Object from Employee Class in Employee.java
			Employee theEmployee = new Employee(name, hourlyRate, hoursWorked);
			//using 3 parameter Constructor to pass already captured data
			
			//call calculatePay Method from Employee.java class
			//calculates and displays employee gross pay
			theEmployee.calculatePay();
			
			System.out.printf( "Employee Name:" + name ); // display employee's name and salary
			System.out.printf( "\nThe Gross Pay This Week is:" + Employee.calculatePay(weeklyPay));
			System.out.printf( " \nYou have now successfully processed the gross pay for." + name);
			
			} while(!name.equalsIgnoreCase("stop"));
		}
	}

AND
/**
 * 
 * Author: Jamie 
 * Date Modified: 04-09-2009 11:06 PM
 * Payroll3 file2 Employee.java
 * Purpose: To calculate weekly salary, then display's the result.
 *
 */

public class Employee 
{
	String employeeName; //declare variables
	double employeeHourlyRate;
	double employeeHoursWorked;
	double salary, weeklyPay;
	
	//use 3 parameter constructor
	public Employee(String name, double hourlyRate, double hoursWorked)
	{
		employeeName = name; //assign parameter values to variables
		employeeHourlyRate = hourlyRate;
		employeeHoursWorked = hoursWorked;
	} //end parameter constructor
	
	public double calculatePay()
	{
		if ( employeeHoursWorked > 40 ) 
		{
			salary = employeeHourlyRate * 40;
			double overtimeSalary = ( employeeHoursWorked - 40 ) * ( employeeHourlyRate * 1.5);
			weeklyPay = salary + overtimeSalary;
		}
		else
		{
			salary = employeeHourlyRate * employeeHoursWorked;
			weeklyPay = salary;
		}
		return weeklyPay;
	
		}//end calculatePay Method
}



Is This A Good Question/Topic? 0
  • +

Replies To: Need help with syntax errors, once again please

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Need help with syntax errors, once again please

Posted 05 September 2009 - 08:01 AM

System.out.printf( "\nThe Gross Pay This Week is:" + Employee.calculatePay(weeklyPay));

calculatepay method doesnt take a param, so you need to fix that. One more thing you may need to check the Employee. part because that is a class and you cant use a class like that if you understand what im saying. its needs to be an evoking object, like,
Employee frank = new Employee();
frank.calculatePay();


Hope this helps!


Edit - Just checked over it again and you need to make it theEmployee.calculatePay(); take out the param and add the "the" part, you created the Employee object likes 3 lines above that

This post has been edited by Fuzzyness: 05 September 2009 - 08:03 AM

Was This Post Helpful? 1
  • +
  • -

#3 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Need help with syntax errors, once again please

Posted 05 September 2009 - 08:07 AM

in the following line
 System.out.printf( "\nThe Gross Pay This Week is:" + Employee.calculatePay(weeklyPay));


calculatePay() does not take a parameter and you are calling it as though it is a static member of Employee - you should call it using the object theEmployee, i.e.
 System.out.printf( "\nThe Gross Pay This Week is:" + theEmployee.calculatePay());


This post has been edited by horace: 05 September 2009 - 08:08 AM

Was This Post Helpful? 0
  • +
  • -

#4 trillian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 25-August 09

Re: Need help with syntax errors, once again please

Posted 05 September 2009 - 08:27 AM

I have made the suggested changes, No errors are recieved during compiling. but I will have to take a deeper look into why I am unable to input the hourlyRate and hoursWorked (they just get skipped).

re-revised code for class Payroll3:
/*
	 * Author: Jamie 
	 * Date Modified: 05-09-2009 11:06 PM
	 * File1: Payroll3
	 * Purpose: To calculate weekly salary, then display's the result.
	 * 
	 */
	import java.util.Scanner; //import Scanner Class for use

	public class Payroll3{
		public static void main(String[] args) 
		{
			Scanner input = new Scanner(System.in); //create Scanner Object
			
			String name = "";	 //declare variables
			double hourlyRate = 0;
			double hoursWorked = 0;
			
			do
			{
			//prompt for user input and receive input
			System.out.println( "\nEnter the name of the employee or type 'stop' to quit: " ); 
			name = input.nextLine();
				
			System.out.println( "Enter the hourly pay rate: " );
				if( hourlyRate <= 0 ) 
				{
					System.out.println( "Positive Number Required"  );
					continue;
				}
			hourlyRate = input.nextDouble();
			
			System.out.println( "Enter the total number of hours worked for this week:  "  ); // prompt
				if( hoursWorked <= 0 ) 
				{		   
					System.out.print( "Positive Number Required " );
					continue;
				}
			hoursWorked = input.nextDouble(); // read second number
			
			//Create Employee Object from Employee Class in Employee.java
			Employee theEmployee = new Employee(hourlyRate, hoursWorked);
			//using 3 parameter Constructor to pass already captured data
			
			//call calculatePay Method from Employee.java class
			//calculates and displays employee gross pay
			theEmployee.calculatePay();
			
			System.out.printf( "Employee Name:" + name ); // display employee's name and salary
			System.out.printf( "\nThe Gross Pay This Week is:" + theEmployee.calculatePay());
			System.out.printf( " \nYou have now successfully processed the gross pay for." + name);
			
			} while(!name.equalsIgnoreCase("stop"));
		}

	}

This post has been edited by trillian: 05 September 2009 - 08:46 AM

Was This Post Helpful? 0
  • +
  • -

#5 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Need help with syntax errors, once again please

Posted 05 September 2009 - 08:28 AM

You must create an employee the way that your constructor goes
public Employee(String name, double hourlyRate, double hoursWorked)

Employee theEmployee = new Employee();
Give that object params or it won't recognize it.
Was This Post Helpful? 0
  • +
  • -

#6 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Need help with syntax errors, once again please

Posted 05 September 2009 - 10:42 AM

View PostFuzzyness, on 5 Sep, 2009 - 02:28 PM, said:

You must create an employee the way that your constructor goes
public Employee(String name, double hourlyRate, double hoursWorked)

Employee theEmployee = new Employee();
Give that object params or it won't recognize it.

as Fuzzyness states fix the call to the constructor, e.g.
			//Create Employee Object from Employee Class in Employee.java
			Employee theEmployee = new Employee(name, hourlyRate, hoursWorked);  // <<< added name


you then have a problem with reading the hourlyRate in that the read is after your if() statement
			System.out.println( "Enter the hourly pay rate: " );
				if( hourlyRate <= 0 )		<< test before the read
				{
					System.out.println( "Positive Number Required"  );
					continue;
				}
			hourlyRate = input.nextDouble();   << read here


you probably need something like
			System.out.println( "Enter the hourly pay rate: " );
			 while((hourlyRate = input.nextDouble()) <= 0 )
				{
					System.out.println( "Positive Number Required"  );
				}


which will loop until the user enter a positive value
you probably have similar errors later on when reading hoursWorked, etc
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1