I have been assigned a task at uni whereby I need to combine two classes. First I need to create the Name Class (code below) and then combine this with the student class so I no longer need to search for the name of the student in the Student Class. I am struggling setting the name so it appears in the Student Class. Can anyone help me with how to create the code so it sets a name to go into the Student Class?
public class Name
{
private String forename;
private String middleName;
private String surname;
/**
* Constructor for objects of class Name
* Set the fields needed to create a full name
*/
public Name(String studentsFirstName, String studentsMiddleName,
String studentsLastName)
{
//instance variables
forename = studentsFirstName;
middleName = studentsMiddleName;
surname = studentsLastName;
}
/**
* A method to change the first name of the student
*/
public void changeFirstName(String replacementFirstName)
{
//change first name
forename = replacementFirstName;
}
/**
* A method to change the middle name of the student
*/
public void changeMiddleName(String replacementMiddleName)
{
//change middle name
middleName = replacementMiddleName;
}
/**
* A method to change the surname of the student
*/
public void changeSurname(String replacementSurname)
{
//change surname
surname = replacementSurname;
}
}