In: Computer Science
Create a java program for Student profile with the following requirements.
To test the program, create a class StudentTest with the main method.
In the main method:
Answer:
import java.util.*;
class Student
{
int id;
String name;
Student() //Default Constructor
{
id=0;
name=null;
}
Student(int newId,String newName) //Parameterized Constructor
{
this.name=newName;
this.id=newId;
}
public void set(int i,String n) //Set Method
{
this.id=i;
this.name = n;
}
public int getid() //Get method for returning ID
{
return id;
}
public String getname() //Get method for returning Name
{
return name;
}
}
public class StudentTest //Test Class
{
public static void main(String[] args) {
Student S1 =new Student();
Student S2 =new Student();
System.out.println(S1.getid());
System.out.println(S1.getname());
System.out.println(S2.getid());
System.out.println(S2.getname());
Student S3 =new
Student(3,"Student_Three");
S3.set(4,"Student_Change");
System.out.println(S3.getid());
System.out.println(S3.getname());
}
}