It looks like a good start.
Let's take it one step at a time...
public class Person
{
// instance variables
private int age;
private String lastName;
private String firstName;
// defined constructor
public Person (String _firstName, String _lastName, int _age)
{
What code do you need to put inside the constructor so that it sets the variables? Give us your best suggestion, and we'll help you out if you get stuck.
You'll also need to think about a couple of other things:
Your program is going to ask for the name and age. You've only defined one constructor, and this constructor requires all the information up front.
If you are going to go down this path, you will need to save the values provided, and then create your person object with those values.
Then you won't need the "setter" methods that you have provided (unless the person changes their name).
If you want to keep the option open of creating a person even if you don't have all the information, then you will need to specify a second constructor that doesn't take any parameters.
Or... you could remove the constructor altogether (which would basically mean that a constructor is made for you. One which doesn't take any parameters).
The getAge() method will do what you need, but there are a couple of things to consider with printAge().
First, I would suggest a name that is more descriptive of what it does, such as setAge(), so as not to confuse your reader.
Second, your parameter is called _age. You will need to use the same name when setting the variable:
return firstName; is not going to show it. If you want to show it, you will have to print it out, for example using
Here you will run into the same problem as with the age. You need to set
As before, you aren't printing, you are setting, and you need to set the variable using the parameter that you are passing in.
Want to clean it up and we'll take it from there?
Is your program going to actually ask for the information, or can the name and age be specified from the command line when you run the program?