Hello everyone! I've worked on this program for about 8 hours so far. I've posted for help in my classroom, and no one has answered. I've passed it in although only one was compiled, but I'm determined to find out why the second did not compile.
It's with the infamous PayRoll Program, here are the instructions - "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. Use a constructor to initialize the
employee information, and a method within that class to calculate the weekly pay. Once
stop is entered as the employee name, the application should terminate."

Here is EmployeeInfo.java This one did compile fine...

// Employee class stores and retrieves employee information
import java.util.Scanner; // program uses class scanner
 
 
public class EmployeeInfo
{
 
   // instance fields
   private String employeeName; // name of employee 
   private double rate; // rate paid to employee
   private double hours; // time employe worked
   
   
 
   // class constructor
   public EmployeeInfo()
   {
      rate = 0.0;
      hours = 0.0;
      employeeName = "";
   } // end class EmployeeInfo constructor
 
   // set rate
   public void setrate(double rate)
   {
      rate = rate;
   } // end method setrate
 
   // get rate
   public double getrate()
   {
      return rate;
   } // end method getrate
 
   // set hours
   public void sethours(double hours)
   {
      hours = hours;
   } // end method sethours
 
   // get hours
   public double gethours()
   {
      return hours;
   } // end method gethours
 
   // set employee name
   public void setemployeeName(String employeeName)
   {
      employeeName = employeeName;
   } // end method setemployeeName
 
   // get employee name
   public String getemployeeName()
   {
      return employeeName;
   } // end method getemployeeName
 
   // calculate and return total
   public double total()
   {
      return rate * hours; // display multiplied rate by hours for weekly pay
   } // end method total
 
} // end class EmployeeInfo

And here is my PayRoll3.java which did not compile, I keep getting cannot find symbol errors. I'd appreciate any help, hints, or tips! Thanks so much!!!

import java.util.Scanner; // program uses class Scanner
public class PayRoll3
{ // begin class PayRoll3
    
   // main method begins execution of Java application
   public static void main( String args[] )
           
   {
        // create Scanner to obtain input from command window
       Scanner input = new Scanner( System.in);
       EmployeeInfo employeeName = new EmployeeInfo( "X");

         String employeeName; // name of employee
         double rate; //Employees Hourly Rate
         double hours; //Employees Hours Worked This Week
         double pay; //Result of Rate * Hours
         
        
        System.out.println();
        System.out.print( "Enter Employees Name or Stop to quit: " );
        //Employee Name Prompt
        
        pay = rate * hours; // multiply numbers

	while ( !employeeName.equals("stop") )
      {
 
         System.out.print( "Enter employee name or 'stop' to quit: "); // prompt
         employeeName = input.next (); // read employee name from user
 
         System.out.print( "Enter hourly rate: " ); // prompt
         rate = input.nextDouble(); // read first number from user
 
         // check if hourly rate is positive number
         if( rate <= 0 )
         {
 
            System.out.print( "Enter a positive amount" );
            System.out.print( "Enter hourly rate: " ); // prompt
            rate = input.nextDouble(); // read first number from user
 
         } // end if
 
         System.out.print( "Enter hours worked: " ); // prompt
         hours = input.nextDouble(); // read second number from user
 
         // check if hours worked is positive number
         if( hours <= 0 )
         {
 
            System.out.print( "Enter a positive amount" );
            System.out.print( "Enter hours worked: " ); // prompt
            hours = input.nextDouble(); // read second number from user
 
         } // end if
 
         
 
         System.out.printf( "Employee \n", employeeName); // display employee name
         System.out.printf( "Weekly pay is $%d\n", pay ); // display weekly pay
 
      } // end while
 
   } // end method main
 
} // end class Payroll3

The error also tells you which symbol (name) cannot be found and the line on which it occurs. Please post the exact error text if you cannot locate it based on the compiler information.

Ooops, sorry.

Here's my error from NetBeans

Compiling 1 source file to C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\PayRoll3\build\classes
C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\PayRoll3\src\payroll3\PayRoll3.java:13: cannot find symbol
symbol : class EmployeeInfo
location: class PayRoll3
EmployeeInfo aEmployee= new EmployeeInfo();

and this one

C:\Documents and Settings\Administrator\My Documents\NetBeansProjects\PayRoll3\src\payroll3\PayRoll3.java:13: cannot find symbol
symbol : class EmployeeInfo
location: class PayRoll3
EmployeeInfo aEmployee= new EmployeeInfo();

Thanks so much!

EmployeeInfo employeeName = new EmployeeInfo( "X");

U r passing value to EmployeeInfo object, but there is no parameterised constructor declared in that class.

And also u r keeping the String name employeeName and object name same which might give error while accessing..
so make it different..

Yes, I did catch the object and string name, so I changed that, now I'll try to change the constructor. Can I ask though, for this type of program (as simple as it may be for most of you), do I have the constructor in the right class? EmployeeInfo, or should I have it in the PayRoll3 class?
I've read and read everything I can (I'm talking at least 12 hours now) and for some reason I haven't found anything that makes sense in my mind. Would you be able to state it clearly?

Thank you so very much for your patience and help :)
Jen

The constructor difference, while it is an error, has nothing to do with the "Cannot find symbol" error. You need to make sure EmployeeInfo is in the same package as "PayRoll3" or add an import statement for that class. The compiler cannot find the class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.