I have two classes. The first class is called EmployeePayRoll.java
(this compiles fine) and the second is called TestEmployeePayRoll.java
(this does not compile). The trouble I'm having is that I'm trying to pass in methods as parameters when I instantiate my objects in the main method of the test class. I've tried a bunch of different things and I just get errors. I've had static/non-static related errors, null pointer errors, etc... I've got some tweaks I'm going to make when I get the test class to compile but this is holding me up. Any advice or suggestions would be appreciated. Thanks!
public class EmployeePayRoll
{
/*** Class Constants ***/
/*** Defaults ***/
public static final String DEFAULT_EMPLOYEE_NAME = "Employee";
public static final double DEFAULT_PAY_RATE = 10.00;
public static final double DEFAULT_HOURS_WORKED = 40.0;
/*** Minimums/Maximums ***/
public static final double MINIMUM_PAY_RATE = 7.25;
public static final double MAXIMUM_PAY_RATE = 20.00;
public static final double MINIMUM_HOURS_WORKED = 0.0;
public static final double MAXIMUM_HOURS_WORKED = 168.0;
/*** Instance Variables***/
public String employeeLastName;
public double hoursWorked;
public double payRate;
/*** Constructors ***/
public EmployeePayRoll( String employeeName,double hours )
{
employeeLastName = employeeName;
hoursWorked = setHoursWorked( hours );
payRate = DEFAULT_PAY_RATE;
}
public EmployeePayRoll( String employeeName, double hours, double hourlyRate )
{
employeeLastName = employeeName;
hoursWorked = setHoursWorked( hours );
payRate = setPayRate( hourlyRate );
}
/*** Mutators ***/
public double setHoursWorked( double hours )
{
if ( verifyHoursWorked ( hours ) )
hoursWorked = hours;
else
hoursWorked = DEFAULT_HOURS_WORKED;
return hoursWorked;
}
public double setPayRate( double hourlyRate )
{
if ( verifyPayRate ( hourlyRate ) )
payRate = hourlyRate;
else
payRate = DEFAULT_PAY_RATE;
return payRate;
}
/*** Accessors ***/
public double getHoursWorked()
{
return hoursWorked;
}
public double getPayRate()
{
return payRate;
}
public double calculateGrossPay()
{
return hoursWorked * payRate;
}
/*** Displays information used to calculate pay ***/
public void displayEmployeeData()
{
System.out.println( "\n\n" );
System.out.println( " Employee: " + employeeLastName + "\n" );
System.out.println( " Hourly Pay Rate: " + "$" + payRate + "\n" );
System.out.println( " Hours Worked: " + hoursWorked + "\n" );
System.out.println( " Gross Pay: " + calculateGrossPay() + "\n" );
}
/*** Helper Methods ***/
public boolean verifyPayRate( double hourlyRate )
{
boolean payRateVerification = false;
if ( hourlyRate >= MINIMUM_PAY_RATE )
{
if ( hourlyRate <= MAXIMUM_PAY_RATE )
{
payRateVerification = true;
}
}
return payRateVerification;
}
public boolean verifyHoursWorked( double hours )
{
boolean hoursVerification = false;
if ( hours >= MINIMUM_HOURS_WORKED )
{
if ( hours <= MAXIMUM_HOURS_WORKED )
{
hoursVerification = true;
}
}
return hoursVerification;
}
}
import java.util.Scanner;
public class TestEmployeePayRoll
{
/*** Instantiates scanner ***/
Scanner scanner = new Scanner( System.in );
/*** Gets input from user ***/
public String inputName()
{
System.out.println( "\n Last name: " );
EmployeePayRoll.employeeLastName = scanner.next();
return EmployeePayRoll.employeeLastName;
}
public double inputPayRate()
{
System.out.println( "\n Pay rate: " );
double rate = scanner.nextDouble();
return EmployeePayRoll.setPayRate( rate );
}
public double inputHoursWorked()
{
System.out.println( "\n Hours: " );
double hrs = scanner.nextDouble();
return EmployeePayRoll.setHoursWorked( hrs );
}
/*** Main method ***/
public static void main( String argv[] )
{
TestEmployeePayRoll test = new TestEmployeePayRoll();
/*** Instantiates employees ***/
EmployeePayRoll employee1 = new EmployeePayRoll( test.inputName(),
test.inputHoursWorked() );
EmployeePayRoll employee2 = new EmployeePayRoll( test.inputName(),
test.inputHoursWorked(),
test.inputPayRate() );
}
}
By the way, I know payroll is one word, but I have to follow from what my professor gave me in the specs.