Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why am i getting this error....PLEASE HELP (Using Constructors)

807603Jun 14 2006 — edited Nov 2 2007
Here is the error i get from the compiler:

No enclosing instance of type PayrollFoundation is accessible. Must qualify the allocation with an enclosing instance of type PayrollFoundation (e.g. x.new A() where x is an instance of PayrollFoundation).

and here is my code for the class:

package Pgm2deClercqMatt;

/**
* @author Owner
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class PayrollFoundation
{
public static void main(String[] args)
{
Emp2 employee1 = new Emp2("Jane", "Smith"); <--------- HERE IS WHERE THE ERROR IS
}

class Emp2
{
private String firstName;
private String lastName;
private double hourlyPayRate, hoursWorked;
private int employeeClassification;

Emp2(String fn, String ln)
{
firstName = fn;
lastName = ln;
}

public void setEmp2(String f, String l)
{
firstName = f;
lastName = l;
}

public void setHourlyPayRate(double rate)
{
hourlyPayRate = rate;
}

public void setHoursWorked(double hours)
{
hoursWorked = hours;
}

public double getGrossPay()
{
double grossPay = 0;

if (hoursWorked <= 40)
{
grossPay = hoursWorked * hourlyPayRate;

}
else
{
grossPay = (40 * (hourlyPayRate + ((1.5 * hourlyPayRate) * hoursWorked - 40)));
}

return grossPay;
}

public String getFirstName(){return firstName;}

public String getLastName(){return lastName;}

public double getHourlyPayRate(){return hourlyPayRate;}

public double getHoursWorked(){return hoursWorked;}

}
}

As you can see it is a simple class in which i am trying to create an object of through the constructor statement in Emp2. If anyone has any input please please please help me.

Matt

Message was edited by:
djmd02
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2007
Added on Jun 14 2006
4 comments
281 views