qpoonz
Active Member
/* The Payroll Class Represents Payroll data for a user entered employee */
public class Payroll
{
//Fields
private String employeeName; //The Employees Name
private int idNumber; //The Employees ID number
private double hourlyPayRate; //How much the Employee makes per hour
private double hoursWorked; //How many hours the employee worked in one week
//Constructor accepts arguments for the employees name, ID Number, pay rate
//and the amount of hours worked.
public Payroll (String employeeName, int idNumber, double hourlyPayRate,
double hoursWorked)
{
employeeName = "ename";
idNumber = number;
hourlyPayRate = hpr;
hoursWorked = hw;
}
//The setEmployeeName method accepts an argument for the employees name
public void setEmployeeName(String ename)
{
employeeName = ename;
}
//The setIdNumber method accepts an argument for the employees ID Number
public void setIdNumber(int number)
{
idNumber = number;
}
//The setPayRate method accepts an argument for the employees hourly pay rate
public void setPayRate(double hpr)
{
hourlyPayRate = hpr;
}
//The setHoursWorked method accepts argument for the amount of hours an employee works
public void setHoursWorked(double hw)
{
hoursWorked = hw;
}
//The getName method returns the employees Name
public String getName()
{
return employeeName;
}
//The getIdNumber method returns the employees ID Number
public int getIdNumber()
{
return idNumber;
}
//The getPayRate method returns the employees hourly pay rate
public double getPayRate()
{
return hourlyPayRate;
}
//The getHoursWorked method returns the amount of hours an employee works
public double getHoursWorked()
{
return hoursWorked;
}
//Calculate gross pay
public double getGrossPay()
{
return (hoursWorked * hourlyPayRate);
}
}
I get this error, i highlighted the lines where these are since the code got all fucked up when i copy pasted it into here:
----jGRASP exec: javac -g Payroll.java
Payroll.java:19: cannot find symbol
symbol : variable number
location: class Payroll
idNumber = number;
^
Payroll.java:20: cannot find symbol
symbol : variable hpr
location: class Payroll
hourlyPayRate = hpr;
^
Payroll.java:21: cannot find symbol
symbol : variable hw
location: class Payroll
hoursWorked = hw;
^
3 errors
Here is the program i plug this into, which seems to be running fine:
//Import scanner utility
import java.util.Scanner;
//This program runs a test of the Payroll Class
public class PayrollTest
{
public static void main(String[] args)
{
String testName; //Hold employee name
int testID; //Hold employee ID Number
double testHPR; //Hold employee Hourly Pay Rate
double testHW; //Hold employee Hours Worked
//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//Get the employee name
System.out.print("What is the employees name?: ");
employeeName = keyboard.nextLine();
//Get the employee ID Number
System.out.print("What is the employees ID Number?: ");
idNumber = keyboard.nextInt();
//Get the employees hourly wage
System.out.print("What is the employees Hourly Pay Rate?: ");
hourlyPayRate = keyboard.nextDouble();
//Get the employees amount of hours worked.
System.out.print("How many hours did the employee work?: ");
hoursWorked = keyboard.nextDouble();
//Calculate Hours worked times hourly wage
//Create an instance of the Payroll Class
//passing the data that was entered as arguements to the constructor
Payroll data = new Payroll(testName, testID, testHPR, testHW);
//Get the data from the employee and display it
System.out.println();
System.out.println("Employee Name: " + data.getName());
System.out.println("Employee ID Number: " + data.getIdNumber());
System.out.println("Employee Pay Rate: " + data.getPayRate());
System.out.println("Employee Hours worked: " + data.getHoursWorked());
}
}
public class Payroll
{
//Fields
private String employeeName; //The Employees Name
private int idNumber; //The Employees ID number
private double hourlyPayRate; //How much the Employee makes per hour
private double hoursWorked; //How many hours the employee worked in one week
//Constructor accepts arguments for the employees name, ID Number, pay rate
//and the amount of hours worked.
public Payroll (String employeeName, int idNumber, double hourlyPayRate,
double hoursWorked)
{
employeeName = "ename";
idNumber = number;
hourlyPayRate = hpr;
hoursWorked = hw;
}
//The setEmployeeName method accepts an argument for the employees name
public void setEmployeeName(String ename)
{
employeeName = ename;
}
//The setIdNumber method accepts an argument for the employees ID Number
public void setIdNumber(int number)
{
idNumber = number;
}
//The setPayRate method accepts an argument for the employees hourly pay rate
public void setPayRate(double hpr)
{
hourlyPayRate = hpr;
}
//The setHoursWorked method accepts argument for the amount of hours an employee works
public void setHoursWorked(double hw)
{
hoursWorked = hw;
}
//The getName method returns the employees Name
public String getName()
{
return employeeName;
}
//The getIdNumber method returns the employees ID Number
public int getIdNumber()
{
return idNumber;
}
//The getPayRate method returns the employees hourly pay rate
public double getPayRate()
{
return hourlyPayRate;
}
//The getHoursWorked method returns the amount of hours an employee works
public double getHoursWorked()
{
return hoursWorked;
}
//Calculate gross pay
public double getGrossPay()
{
return (hoursWorked * hourlyPayRate);
}
}
I get this error, i highlighted the lines where these are since the code got all fucked up when i copy pasted it into here:
----jGRASP exec: javac -g Payroll.java
Payroll.java:19: cannot find symbol
symbol : variable number
location: class Payroll
idNumber = number;
^
Payroll.java:20: cannot find symbol
symbol : variable hpr
location: class Payroll
hourlyPayRate = hpr;
^
Payroll.java:21: cannot find symbol
symbol : variable hw
location: class Payroll
hoursWorked = hw;
^
3 errors
Here is the program i plug this into, which seems to be running fine:
//Import scanner utility
import java.util.Scanner;
//This program runs a test of the Payroll Class
public class PayrollTest
{
public static void main(String[] args)
{
String testName; //Hold employee name
int testID; //Hold employee ID Number
double testHPR; //Hold employee Hourly Pay Rate
double testHW; //Hold employee Hours Worked
//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
//Get the employee name
System.out.print("What is the employees name?: ");
employeeName = keyboard.nextLine();
//Get the employee ID Number
System.out.print("What is the employees ID Number?: ");
idNumber = keyboard.nextInt();
//Get the employees hourly wage
System.out.print("What is the employees Hourly Pay Rate?: ");
hourlyPayRate = keyboard.nextDouble();
//Get the employees amount of hours worked.
System.out.print("How many hours did the employee work?: ");
hoursWorked = keyboard.nextDouble();
//Calculate Hours worked times hourly wage
//Create an instance of the Payroll Class
//passing the data that was entered as arguements to the constructor
Payroll data = new Payroll(testName, testID, testHPR, testHW);
//Get the data from the employee and display it
System.out.println();
System.out.println("Employee Name: " + data.getName());
System.out.println("Employee ID Number: " + data.getIdNumber());
System.out.println("Employee Pay Rate: " + data.getPayRate());
System.out.println("Employee Hours worked: " + data.getHoursWorked());
}
}