I need help with my code

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;
}
}

Hello, @method9896207539, and welcome to the forums.

You’ve put this in the JavaScript category. It sure doesn’t look like JavaScript. C# maybe?

Also, for us to be more helpful, it helps if you format your code. For a block of code, it should appear between two otherwise blank lines that have three back ticks sometimes called back quotes on each:

```
code goes here
```

I’m using bluej which uses javascript, so I assumed it would go in java?

I’ve not heard of blueJ until now. Looks like it helps folks write Java code. Java was my next guess, but I don’t see a main method in your Name class. Perhaps bluej adds that later, or you just didn’t include it in the code you pasted? Anyhow, I took a gaze at BlueJ’s documentation. It includes some instructions on ‘dependencies’. You should check that out, or you could write the code yourself. You might google something like, ‘Java extends’.

Thank you! I’ll have a look at that :slight_smile:

1 Like