TECH Need help with Java Homework: Cannot find symbol error

qpoonz

Active Member
Apr 24, 2005
3,867
Clearwater, Fl
/* 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());

}
}
 

critter783

OT Supporter
Jul 15, 2005
1,782
In the lines you highlighted, you're assigning your class members to variables that don't exist.
 

Users who are viewing this thread

About Us

  • Please do not post anything that violates any Local, State, Federal or International Laws. Your privacy is protected. You have the right to be forgotten. Site funded by advertising, link monetization and member support.
OT v15.8.1 Copyright © 2000-2022 Offtopic.com
Served by fu.offtopic.com

Online statistics

Members online
262
Guests online
60
Total visitors
322

Forum statistics

Threads
369,746
Messages
16,916,424
Members
86,875
Latest member
ddunn9448