I'm doing a homework assignment... I have two files. Payroll (the class) and myPayroll.
I run myPayroll and it does everything except return the employee's name and ID number.
I'm supposed to pass those values to the constructor... but i'm at a loss as to how to do that.
First file: Payroll
// Assignment #3 IS115: Introduction to Programming
// Author: Brian Wikene
// Due Date: 10/25/2008
public class Payroll
{
private String empName; // holds the Employee Name
private String empId; // holds the Employee ID
private double empPR; // holds the Employee Pay Rate
private double empHR; // holds the Employee Hours Worked
private double grossPay; // holds the Employee Gross Pay
/**
Setters
*/
public void setempName(String Name)
{
empName = Name;
}
public void setempId(String Id)
{
empId = Id;
}
public void setempPR(double payRate)
{
empPR = payRate;
}
public void setempHR(double hours)
{
empHR = hours;
}
/**
Getters
*/
public String getempName()
{
return empName;
}
public String getempId()
{
return empId;
}
public double getempPR()
{
return empPR;
}
public double getempHR()
{
return empHR;
}
public double getgrossPay()
{
return empPR * empHR;
}
}
Second file: myPayroll
import java.util.Scanner; // Needed for the Scanner class
public class myPayroll
{
public static void main(String[] args)
{
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
// Get the Employee's Name.
System.out.print("Enter the Employee Name ");
String empName = keyboard.nextLine();
// Get the Employee's ID
System.out.print("Enter the Employee ID Number ");
String empID = keyboard.nextLine();
// Get the Employee's PayRate
System.out.print("Enter the Employee Rate of Pay ");
double empPR = keyboard.nextDouble();
// Get the Employee's Hours Worked
System.out.print("Enter the Employee Work Hours ");
double empHR = keyboard.nextDouble();
// Create a new object.
Payroll pay = new Payroll()
pay.setempPR(empPR);
pay.setempHR(empHR);
// ******************************************************************
// * Data Output *
// ******************************************************************
System.out.println("\n+++++++++++++++++++++++++++++++++");
System.out.println("+ Current Employee Payroll Data +");
System.out.println("+++++++++++++++++++++++++++++++++");
System.out.println("\nEmployee Name: " + pay.getempName());
System.out.println("Employee ID: " + pay.getempId());
System.out.println("Employee Pay Rate $" + pay.getempPR());
System.out.println("Employee Hours Worked " + pay.getempHR());
System.out.println("Employee Gross Wages $" + pay.getgrossPay());
}
}
I tried to put my variables empName and empID in the paren for the new object, but it won't compile... I'm lost. I'm not looking for anyone to do the work for me - I genuinely want to learn what to do.