In Java Develop a simple class for a Student Include class v
In Java:
Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName,
GPA (double), and Major. Extend your class for a Student to include classes for Graduate and Undergraduate.
o Include a default constructor, a constructor that accepts the above information, and a
method that prints out the contents FOR EACH LEVEL of the object, and a method that
prints out the contents of the object.
o Write a program that uses an array of Students in a course. Input the Student information,
create the object, and add each student to the list. Use a StudentID of -1 as a sentinel value.
o Print out the Students in the list.
Solution
Answer :-
class StudentDetails
{
public static void main(String s[])
{
Student students[] = new Student[5];
students[0] = new Student();
students[0].StudentID = 1001;
students[0].FirstName = \"Rajesh\";
students[0].LastName = \"K\";
students[0].GPA = \'3.2\';
students[1] = new Student();
students[0].StudentID = 1002;
students[0].FirstName = \"Suresh\";
students[0].LastName = \"S\";
students[0].GPA = \'4.5\';
students[2] = new Student();
students[0].StudentID = 1003;
students[0].FirstName = \"Ramesh\";
students[0].LastName = \"k\";
students[0].GPA = \'4\';
students[3] = new Student();
students[0].StudentID = 1004;
students[0].FirstName = \"Kamlesh\";
students[0].LastName = \"j\";
students[0].GPA = \'3.5\';
students[4] = new Student();
students[0].StudentID = 1005;
students[0].FirstName = \"Vignesh\";
students[0].LastName = \"A\";
students[0].GPA = \'3\';
for(int i = 0; i < students.length; i++)
{
System.out.println(\"StudentID\"+ students[i].StudentID + \"Student FirstName \" + students[i].FirstName + \"Student LastName \" + students[i].LastName + students[i].GPA+\"out of 5\");
}
}
}
class Student
{
int StudentID;
String FirstName;
String LastName;
String address;
double GPA;
}

