2 Develop a simple class for a Student Include class variabl
2. 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
Driver program:
I\'m currently learning inheritance in java. I have a superclass called Students with subclasses UndergradStudents & GraduateStudents. Both of them have a method called deansHonourList. In the undergrad deansHonourList method it checks if the GPA is greater than 3.5 to qualify for the deans list and for the graduate subclass the gpa has to be greater than 3.75, I have to remove the methods in the subclasses and create one method in the superclass that determines if the student qualifies for the deans honour list. Here is my code so far.
| I\'m currently learning inheritance in java. I have a superclass called Students with subclasses UndergradStudents & GraduateStudents. Both of them have a method called deansHonourList. In the undergrad deansHonourList method it checks if the GPA is greater than 3.5 to qualify for the deans list and for the graduate subclass the gpa has to be greater than 3.75, I have to remove the methods in the subclasses and create one method in the superclass that determines if the student qualifies for the deans honour list. Here is my code so far. import java.io.*; public class execute { public static void main(String[] args) { Student[] students = new Student[4]; students[0] = new UndergradStudent(5011, \"Casper\",\"martin\", 2.78, 2); students[1] = new Graduate(3044, \"Sheena\",\"marwaha\" 3.92, 1992)); students[2] = new UndergradStudent(6170, \"Yolanda\",\"mary\", 4.26, 3); students[3] = new Graduate(1755, \"Geordi\", 3.58, \"Human-Computer Interaction\"); printStudents(students); printDeansList(students); System.out.println(\"\ End of processing.\"); } public static void printStudents(Student[] students) { System.out.println(\"\ List of all students:\ \"); for (int i = 0; i < students.length; i++) { System.out.println(i + 1 + \": \" + students[i]); } } public static void printDeansList(Student[] students) { System.out.println(\"\ Dean\'s honour list:\ \"); for (int i = 0; i < students.length; i++) { if (students[i].deansHonourList()) { System.out.println(students[i]); } } } } |
