Part 1: Objects and Class Headers
Create file Lab7.java with a main method. Inside your main method, write a segment of code which instantiates an object of the Student class (This class has been created for you in the Student.java file that is provided as part of this lab).
Now, for the Student object you created, set its name and age as your own name and age. Next, we will print the Student details by calling thetoString method.
Hint: Below is a segment of code, which sets the name and age of Student
Student stInstance = new Student("Eric",28);
Next, prompt the user to enter a new age. Store the input in the variablenewAge.
Use the setAge method to set the age of stInstance to the age that you just read from the user. The user should receive the following prompt and the inputs should be stored into newAge.
"Please enter student's new age: "
Next, display the Student details again, and note how the age has been changed.
// The Student.java file is this:
/*
/**
** Do NOT edit this file!!
**/
// This is the class header for the class Student
public class Student
{
// Declaring the variables
private String name;
private int age;
// Declaring the constructor for the Student class
public Student(String someName, int someAge)
{
name=someName;
age=someAge;
}
// Declaring the toString method which returns a String representation of the object.
public String toString()
{
return ("Name is \t:"+name+"\nAge is \t\t:"+age);
}
// Declaring the setAge method which sets the age of the Student object
public void setAge(int newAge)
{
age= newAge;
}
}
*/