I'm trying to write a program for a class that creates a payroll stub. I've looked at work online and I'm trying to create my own version, but I keep getting errors revolving around what my main() is, and it wont run correctly.
I've tried reorganizing the code, creating a new file, and renaming things, but I still get the following exception:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type Employee is accessible. Must qualify the allocation with an enclosing instance of type Employee (e.g. x.new A() where x is an instance of Employee).
at Employee.main(Employee.java:8)
I expected the ability to input these values in my code:
import java.util.Scanner;
import java.util.*;
public class Employee{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
PayStub data = new PayStub();
System.out.println("Enter name: ");
data.setName(input.next());
System.out.println("Enter address: ");
data.setAddress(input.next());
System.out.println("Enter SSN: ");
data.setSSN((input.next()));
System.out.println("Number of hours: ");
data.setHoursWorked(Double.parseDouble(input.next()));
System.out.println("Enter hourly rate: ");
data.setHourlyPayRate(Double.parseDouble(input.next()));
input.close();
}
}
public class PayStub {
private String name;
private double hoursWorked;
private double hourlyRate;
private double fedTaxRate;
private double stateTaxRate;
private String address;
private String phone;
private String SSN;
public PayStub() {
}
public PayStub(String n, double w, double p) {
this.name = n;
this.hoursWorked = w;
this.hourlyRate = p;
}
public double grossPay(double hr, double hw) {
double grossPay = (hourlyRate * hoursWorked);
return grossPay;
}
public void setFedTax(double fedTaxRate) {
this.fedTaxRate = fedTaxRate;
}
public double getFedTax() {
return fedTaxRate;
}
public void setStateTax(double stateTaxRate) {
this.stateTaxRate = stateTaxRate;
}
public double getStateTax() {
return stateTaxRate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getHoursWorked() {
return hoursWorked;
}
public void setHoursWorked(double hoursWorked) {
this.hoursWorked = hoursWorked;
}
public double getHourlyPayRate() {
return hourlyRate;
}
public void setHourlyPayRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}
public String getAddress(){
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhone(){
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getSSN() {
return SSN;
}
public void setSSN(String SSN) {
this.SSN = SSN;
}
}