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