can someone explain what variables do what in beginning Java? I am confused about what the variables point to in the bit of code I am doing for my computer class. I am too new to even know what to search for to get the right answer and the book I am using doesn't help explain anything as it names all the variables the same which confuses me on what is called from where. Thank you Chad
Where does the public void setEmpID(int NewID)
set this.empID to NewID?
// access modifier is set to public and a class is declared and named Employee
public class Employee
{
private int empID;
private String firstName;
private String lastName;
private double monthlySalary; (Are these to store the variable values from the main method until class creation or are they defining variables in the object that will be created?)
//Constructor intializes class Employee to create object Employee with instance variables above. Must be same name as class
**public Employee(int empID, String firstName, String lastName, double newSalary) //(is this the storage until the class is created or the defining of the variables for the object that will be created?)**
{
//ensures empID is a positive number before assignment
if (empID > 0.0)
//assigns empID to variable "empID"
**this.empID = empID; //where does this assign empID? in the new object or in this class temporarily until the object is created?**
//assigns firstName to variable "firstName"
this.firstName = firstName;
// assigns lastName to variable "lastName"
this.lastName = lastName;
//ensure monthlySalary is a positive number before assignmentand if
//ends constructor
}
**//method that sets the empID(where are these set?)**
public void setEmpID(int newID)
{
this.empID = newID;
}
//method that sets the firstName
public void setFirstName(String newFirst)
{
this.firstName = newFirst;
}
//method that sets the lastName
public void setLastName(String newLast)
{
this.lastName = newLast;
}
//method that sets the monthlySalary for the new obj
public void setMonthlySalary(double newSalary)
{
this.monthlySalary = newSalary;
}
**//Gets empid from the object and returns empID to the calling method (I think this is right)**
public int getEmpID()
{
return empID;
}
//gets first name from the object and returns first name to the calling method
public String getFirstName()
{
return firstName;
}
//gets last name from the object and returns last name to the calling method
public String getLastName()
{
return lastName;
}
//gets monthly salary from the object and returns it to the calling method
public double getMonthlySalary()
{
return monthlySalary;
}
}