I'm getting error messages when I run my program. The problem is as follows:
Design a Payroll class that has fields for an employee's name, ID number, hourly pay rate, and number of hours worked. Write the appropriate accessor and mutator methods and a constructor that accepts the employee's name and ID number as arguments. The class should also have a method that returns the employee's gross pay, which is calculated as the number of hours worked multiplied by the hourly rate. Write a program that demonstrates the class by creating a Payroll object, then asking the user to enter the data for an employee. The program should display the amount of gross pay earned.
My code is as follows. I have a Payroll class and Payroll demo files:
// Payroll3.java
// This is a class called Payroll3 that holds different data for an employee.
// Chapter 6, #3.
public class Payroll3
{
private String EmployeeName; // Name
private int ID; // Address
private double HourlyPay;
private double HoursWorked;
private double WeeklyPay;
Payroll3(String startEmployeeName, String startID, double startHourlyPay, double startHoursWorked, double startWeeklyPay)
{
EmployeeName = startEmployeeName;
ID = (int) ID;
HourlyPay = startHourlyPay;
HoursWorked = startHoursWorked;
WeeklyPay = startWeeklyPay;
}
public String getEmployeeName(String EmployeeName)
{
return EmployeeName;
}
public int getID()
{
return ID;
}
public double getHourlyPay()
{
return HourlyPay;
}
public double setHoursWorked()
{
return HoursWorked;
}
public double WeeklyPay()
{
return WeeklyPay;
}
}
import java.util.Scanner;
public class Payroll3Demo
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//declare variables
String EmployeeName;
int ID;
double HourlyPay;
double HoursWorked;
double WeeklyPay;
// create scanner to input data
java.util.Scanner input = new Scanner(System.in);
//Prompt to enter employee name
System.out.print("Enter the Employee Name: ");
EmployeeName = input.nextLine();
//Prompt to enter employee ID
System.out.print("Enter the Employee ID: ");
ID=input.nextInt();
// Prompt for hourly pay rate
System.out.print("Enter hourly pay rate: $");
HourlyPay=input.nextDouble();
//Prompt for number of hours worked
System.out.print("Enter number of hours worked: ");
HoursWorked=input.nextDouble();
//state weekly pay amount
System.out.print("Weekly Salary is: $" + HourlyPay*HoursWorked);
WeeklyPay=input.nextDouble();
// Display the data.
System.out.println("Name: " + startEmployeeName.setEmployeeName());
System.out.println("ID: " + startID.setID());
System.out.println("Hourly rate: " + startHourlyPay.setHourlyPay());
System.out.println("Hours worked: " + startHoursWorked.setHoursWorked());
System.out.println("Weekly salary: " + startWeeklyPay.setWeeklyPay());
System.out.println();
}//end method main
}//end class Payroll3
When I compile Payroll3Demo, the following errors are displayed:
Payroll3Demo.java:47: cannot find symbol
symbol : variable startEmployeeName
location: class Payroll3Demo
System.out.println("Name: " + startEmployeeName.setEmployeeName());
^
Payroll3Demo.java:48: cannot find symbol
symbol : variable startID
location: class Payroll3Demo
System.out.println("ID: " + startID.setID());
^
Payroll3Demo.java:49: cannot find symbol
symbol : variable startHourlyPay
location: class Payroll3Demo
System.out.println("Hourly rate: " + startHourlyPay.setHourlyPay());
^
Payroll3Demo.java:50: cannot find symbol
symbol : variable startHoursWorked
location: class Payroll3Demo
System.out.println("Hours worked: " + startHoursWorked.setHoursWorked());
^
Payroll3Demo.java:51: cannot find symbol
symbol : variable startWeeklyPay
location: class Payroll3Demo
System.out.println("Weekly salary: " + startWeeklyPay.setWeeklyPay());
^
5 errors