I am new to programming, so please accept my apologies if this question is simple.
I have a class (say called Student).
I want to store the name of the student (name) and the course (course)
I have declared some variables in my Student class:
private String name = " "; //Holds the data for name
private String course = " "; //Holds the data for course
I have declared a constructor for my Student class:
Student (String studentName, String studentCourse)
{
name = studentName;
course = studentCourse;
}//end constructor Student
I have declared some methods in my Student class:
//This method returns a String with the contents of the variable
//name to whatever object calls it
public String getName ( )
{
return name;
}//end method getName
//This method allows the contents of name to be changed
//to store a different String value, should that be required
public void setName (String studentName)
{
name = studentName;
}//end method setName
public String getCourse ( )
{
return course;
}//end method getCourse
public void setCourse (String studentCourse)
{
course = studentCourse;
}//end method setCourse
In another method called hashCode, I change the name varable in my Student class to upperCase i.e.
public int hashCode (int numStudents)
{
int hash = 0;
int subtotal = 0;
int maxNum = 0;
//Convert name to upper case
name = name.toUpperCase ( );
And then use the upper case name variable to calculate my hash code.
What I would like to know is this the best way of doing things? Or should I be using the setName method to change the name variable to upper case?
Also, does anyone know of any online resources where I can look at the set/get methods? (My course notes are very limited).
Thanking you in advance.