Programming Assignment: Inheritance and Polymorphism

Instructions:

  1. You are about to write an object-oriented program using inheritance and polymorphism to simulate a student tracking system. You'll consider adding the following classes in your design:

    Person
    Properties: name (:String) and age (:int). In additon, to keep track of the number of Person being created, you need to additional property that is a class variable (:static int). Methods include a parameterized constructor, a print method, and a method that returns the number of Person objects created.
    Student
    Properties: GPA. Methods include a parameterized constructor and a print. If the GPA of a student is 3.5 or above, print out additional message: "Made Dean's honor list."
    CollegeStudent
    Properties: major(:String) and university this student is attending(:University). Methods include a parameterized constructor, a print, and a method that changes the major of this student.
    University
    Properties: school name (:String). Methods include a default constructor, a parameterized constructor and a print method. If the user does not provide any name for the university, use a message as default school name: "The university name has not been provided."
    When you design the program, you need to consider the inheritance relationships among the classes. Use the main method in class TestStudent as a guide to implement the classes. Note that you are NOT allowed to change the main method. In addition, define the member variables (both instance and static) as private and the methods and constructors as public. Once your program works correctly, it should print out the output given at the bottom of this instructions.

    A skeleton code for class TestStudent:

    public class TestStudent {
    	public static void main(String[] args) {
    		University wesleyan = new University("Texas Wesleyan University, Fort Worth, Texas");
    		University rice = new University("Rice University, Houston, Texas");
    		University cornell = new University("Cornell University, Ithaca, New York");
    		
    		Person jackiePerez = new CollegeStudent("Jackie Perez", 21, 3.58, "Computer Science", wesleyan);
    		System.out.println("\n---------------------- 1 ---------------------");
    		jackiePerez.print();
    
    		Person erikaSmart = new CollegeStudent("Erika Smart", 25, 2.3, "Biology", rice);
    		System.out.println("\n---------------------- 2 ---------------------");
    		erikaSmart.print();
    		if (erikaSmart instanceof CollegeStudent)
    			((CollegeStudent)erikaSmart).changeMajor("General Business");
    		System.out.println("\n---------------------- 3 ---------------------");
    		erikaSmart.print();
    
    		Student joMiller = new CollegeStudent("Jo Miller", 19, 2.85, "Liberal Arts", new University());
    		System.out.println("\n---------------------- 4 ---------------------");
    		joMiller.print();
    
    		CollegeStudent veronikaVasylenko = new CollegeStudent("Veronika Vasylenko", 22, 3.95, "Mechanical Engineering", cornell);
    		System.out.println("\n---------------------- 5 ---------------------");
    		veronikaVasylenko.print();
    		
    		System.out.println("\n" + Person.getPersonCount() + " Person objects have been created.");
    	}
    }
    
  2. Sample output:
    // ---------------------- 1 ---------------------
    // Jackie Perez is 21 years old. GPA is 3.58.
    // Made Dean's honor list.
    // Major in Computer Science.
    // Attending Texas Wesleyan University, Fort Worth, Texas
    // ---------------------- 2 ---------------------
    // Erika Smart is 25 years old. GPA is 2.3.
    // Major in Biology.
    // Attending Rice University, Houston, Texas
    // ---------------------- 3 ---------------------
    // Erika Smart is 25 years old. GPA is 2.3.
    // Major in General Business.
    // Attending Rice University, Houston, Texas
    // ---------------------- 4 ---------------------
    // Jo Miller is 19 years old. GPA is 2.85.
    // Major in Liberal Arts.
    // Attending The university name has not been provided.
    // ---------------------- 5 ---------------------
    // Veronika Vasylenko is 22 years old. GPA is 3.95.
    // Made Dean's honor list.
    // Major in Mechanical Engineering.
    // Attending Cornell University, Ithaca, New York
    
    // 4 Person objects have been created.