Payroll Program Part 3 - Can someone offer advice (point me in the rig

Two compile Errors - 'Cannot Find Symbol' ???? I'm stuck&

Page 1 of 1

2 Replies - 4468 Views - Last Post: 22 August 2009 - 07:31 PM Rate Topic: -----

#1 Buttafly101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 16-April 09

Payroll Program Part 3 - Can someone offer advice (point me in the rig

Post icon  Posted 22 August 2009 - 11:10 AM

/** Modify the Payroll Program so that it uses a class to store and retrieve the employee's 
	name, the hourly rate, and the number of hours worked. */
/** Program should continue to check the hourly rate and number of hours worked are positive
	numbers; if either the hourly rate or the number of hours worked is not a positive value,  
	then prompt the user to enter a positive value. */
//  Use a constructor to initialize the employee information.
//  Use a method within the class to calculate the weekly pay.
//  Once 'stop' is entered as the employee name, the application should terminate.
import java.util.Scanner; // program uses class Scanner

public class Payroll3
{
	// main method begins execution of Java application
	public static void main( String args[] )
	{
		boolean stop = false; // Loop will run as long as 'stop' is not input by user	
			
		do
		{
		// create Scanner to obtain input from Command Prompt window.
		Scanner input = new Scanner( System.in );
		
		String nameOfEmployee; // employee's name		
		double hrlyPay; // first number used to multiply
		double hrsWrkd; // second number used to multiply
		double product; //product of hrlyPay and hrsWrkd		
		String Employee;
		
			System.out.print( "\nPlease enter Employee's full name:\n " ); // prompt
			nameOfEmployee = input.nextLine(); // read line of text entered by user
			
				if ( nameOfEmployee.toLowerCase().equals( "stop" ) )
				{
					System.out.print( "You have entered Stop! The program will now terminate.\n" );
					System.out.print( "GoodBye!\n" );	
					stop = true;
				}
			else 
			{
				System.out.print( "\nPlease enter Employee's full name:\n " ); // prompt
				nameOfEmployee = input.nextLine(); // read line of text entered by user
			}
				
			System.out.print( "\nEnter your hourly wage:\n$ " ); // prompt
			hrlyPay = input.nextDouble(); // read hourly pay input from user
			
				while( hrlyPay < 0 )
				{
					System.out.print( "\nInvalid entry! Enter positive numbers only.\n" ); // entry error message displayed
					System.out.print( "Please enter a valid hourly wage:\n$ " ); // prompt
					hrlyPay = input.nextDouble(); // loop until valid hourly wage is input by user
				} // end while
			
			System.out.print( "\nEnter hours worked for the week:\n " ); // prompt
			hrsWrkd = input.nextDouble(); // read hours worked input from user
				
				while( hrsWrkd < 0 ) 
				{
					System.out.print( "\nInvalid entry! Enter positive numbers only.\n" ); // entry error message displayed
					System.out.print( "Please enter valid hours worked for the week:\n " ); // prompt
					hrsWrkd = input.nextDouble(); // read hours worked input from user
				} // end while
				
			Employee employee = new Employee( nameOfEmployee, hrlyPay, hrsWrkd );
			
			System.out.printf( "\n%s\n", nameOfEmployee ); // display employee name
		
			System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.
		
		} 	while( stop == false );
			
	} // end main

} // end class Payroll3





The two compile errors I receive are:
Payroll3.java:65: cannot find symbol
symbol  : method getName()
location: class java.lang.String
			System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.
																		^
Payroll3.java:65: cannot find symbol
symbol  : method calcWklyPay()
location: class java.lang.String
			System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.



Same line of code...I thought I had the methods for getName() and calcWklyPay() declared in my Class Employee
// Class Employee

public class Employee
{
	// private variable containers
	private String nameOfEmployee;
	private double hrlyPay;
	private double hrsWrkd;
	
	// 3 constuctor arguments for creating employee object
	public Employee( String Name, double Wage, double Hours )
	{
		this.nameOfEmployee = Name;
		this.hrlyPay = Wage;
		this.hrsWrkd = Hours;
	}
	// Methods for retrieving user input information
	public String getName()
	{
		return this.nameOfEmployee; // read user input; Employee Name
	}
	
	public double getWage()
	{
		return this.hrlyPay; // read user input; Employee Wage
	}
	
	public double getHours()
	{
		return this.hrsWrkd; // read user input; Hours Worked
	}
	
	public double calcWklyPay()
	{
		return this.hrlyPay * hrsWrkd; // calculate and display total weekly pay
	}
	
} // end Class Employee	



I have been working on this (after work) for days and I can't seem to figure out what I am missing/overlooking.

Is This A Good Question/Topic? 0
  • +

Replies To: Payroll Program Part 3 - Can someone offer advice (point me in the rig

#2 Buttafly101  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 16-April 09

Re: Payroll Program Part 3 - Can someone offer advice (point me in the rig

Posted 22 August 2009 - 12:04 PM

View PostButtafly101, on 22 Aug, 2009 - 10:10 AM, said:

/** Modify the Payroll Program so that it uses a class to store and retrieve the employee's 
	name, the hourly rate, and the number of hours worked. */
/** Program should continue to check the hourly rate and number of hours worked are positive
	numbers; if either the hourly rate or the number of hours worked is not a positive value,  
	then prompt the user to enter a positive value. */
//  Use a constructor to initialize the employee information.
//  Use a method within the class to calculate the weekly pay.
//  Once 'stop' is entered as the employee name, the application should terminate.
import java.util.Scanner; // program uses class Scanner

public class Payroll3
{
	// main method begins execution of Java application
	public static void main( String args[] )
	{
		boolean stop = false; // Loop will run as long as 'stop' is not input by user	
			
		do
		{
		// create Scanner to obtain input from Command Prompt window.
		Scanner input = new Scanner( System.in );
		
		String nameOfEmployee; // employee's name		
		double hrlyPay; // first number used to multiply
		double hrsWrkd; // second number used to multiply
		double product; //product of hrlyPay and hrsWrkd		
		String Employee;
		
			System.out.print( "\nPlease enter Employee's full name:\n " ); // prompt
			nameOfEmployee = input.nextLine(); // read line of text entered by user
			
				if ( nameOfEmployee.toLowerCase().equals( "stop" ) )
				{
					System.out.print( "You have entered Stop! The program will now terminate.\n" );
					System.out.print( "GoodBye!\n" );	
					stop = true;
				}
			else 
			{
				System.out.print( "\nPlease enter Employee's full name:\n " ); // prompt
				nameOfEmployee = input.nextLine(); // read line of text entered by user
			}
				
			System.out.print( "\nEnter your hourly wage:\n$ " ); // prompt
			hrlyPay = input.nextDouble(); // read hourly pay input from user
			
				while( hrlyPay < 0 )
				{
					System.out.print( "\nInvalid entry! Enter positive numbers only.\n" ); // entry error message displayed
					System.out.print( "Please enter a valid hourly wage:\n$ " ); // prompt
					hrlyPay = input.nextDouble(); // loop until valid hourly wage is input by user
				} // end while
			
			System.out.print( "\nEnter hours worked for the week:\n " ); // prompt
			hrsWrkd = input.nextDouble(); // read hours worked input from user
				
				while( hrsWrkd < 0 ) 
				{
					System.out.print( "\nInvalid entry! Enter positive numbers only.\n" ); // entry error message displayed
					System.out.print( "Please enter valid hours worked for the week:\n " ); // prompt
					hrsWrkd = input.nextDouble(); // read hours worked input from user
				} // end while
				
			Employee employee = new Employee( nameOfEmployee, hrlyPay, hrsWrkd );
			
			System.out.printf( "\n%s\n", nameOfEmployee ); // display employee name
		
			System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.
		
		} 	while( stop == false );
			
	} // end main

} // end class Payroll3





The two compile errors I receive are:
Payroll3.java:65: cannot find symbol
symbol  : method getName()
location: class java.lang.String
			System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.
																		^
Payroll3.java:65: cannot find symbol
symbol  : method calcWklyPay()
location: class java.lang.String
			System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.



Same line of code...I thought I had the methods for getName() and calcWklyPay() declared in my Class Employee
// Class Employee

public class Employee
{
	// private variable containers
	private String nameOfEmployee;
	private double hrlyPay;
	private double hrsWrkd;
	
	// 3 constuctor arguments for creating employee object
	public Employee( String Name, double Wage, double Hours )
	{
		this.nameOfEmployee = Name;
		this.hrlyPay = Wage;
		this.hrsWrkd = Hours;
	}
	// Methods for retrieving user input information
	public String getName()
	{
		return this.nameOfEmployee; // read user input; Employee Name
	}
	
	public double getWage()
	{
		return this.hrlyPay; // read user input; Employee Wage
	}
	
	public double getHours()
	{
		return this.hrsWrkd; // read user input; Hours Worked
	}
	
	public double calcWklyPay()
	{
		return this.hrlyPay * hrsWrkd; // calculate and display total weekly pay
	}
	
} // end Class Employee	



I have been working on this (after work) for days and I can't seem to figure out what I am missing/overlooking.


I figured out (finally!) why I was getting the 2 compile errors...
System.out.printf( "Your weekly pay is: $%.2f\n\n", Employee.getName(), Employee.calcWklyPay() ); // Get inputs from Employee class - multiply and display weekly pay.


Because I had employee capitalized.
However, now that is fixed I am getting a runtime error for the same line of code (65).
Your weekly pay is: $Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.String
	at java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:3999)
	at java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:2722)
	at java.util.Formatter$FormatSpecifier.print(Formatter.java:2667)
	at java.util.Formatter.format(Formatter.java:2433)
	at java.io.PrintStream.format(PrintStream.java:920)
	at java.io.PrintStream.printf(PrintStream.java:821)
	at Payroll3.main(Payroll3.java:65)


This one I am not understanding...I am asking the output in that part to be a floating point or double with 2 decimal places...just isn't working. What can I do?
Was This Post Helpful? 0
  • +
  • -

#3 Atspulgs  Icon User is offline

  • D.I.C Regular

Reputation: 68
  • View blog
  • Posts: 380
  • Joined: 29-July 09

Re: Payroll Program Part 3 - Can someone offer advice (point me in the rig

Posted 22 August 2009 - 07:31 PM

Its the same line you pointed out that had capitalized employee.

must be this (i think)
System.out.printf( "Your weekly pay is: $%.2f\n\n", employee.calcWklyPay() );



instead of
System.out.printf( "Your weekly pay is: $%.2f\n\n", employee.getName(), employee.calcWklyPay() );



you have shown that youll be displaying a double only yet you try to display name what happened to be of a String type.

P.S. your program is re-asking the name twice for one calculation and also stop isnt working properly. I think you might want to look into that.

This post has been edited by Atspulgs: 22 August 2009 - 07:39 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1