Question
In this lab, we create a few classes to represent students in a university. A university (name has to be entered by the user) has
In this lab, we create a few classes to represent students in a university. A university (name has to be entered by the user) has students registered with them (number of students has to be entered by the user). Each student has common attributes of a person (first name, last name, email, and phone number) and a GPA, which is calculated based on the marks obtained in various courses (number of courses can vary). We have fulltime students and part time students, each of them has different attributes. In order to implement this system, you need to create the following interface and classes:
Person (Interface)
Instance variables: firstName(String), lastName(String), emailId(String), phoneNumber (long). Student class will be implementing this interface. So, think about the access specifiers for the instance variables. (Should these ones be here? ), think and decide.
Constructor: do you need a no-arg constructor??? Think and decide!
Methods: readInfo(), printInfo() (both methods accepts nothing, returns nothing). Think and decide if they should be abstract or not.
NOTE: You are permitted to make changes to your program to make it work - but highlight those changes in code comments. Whatever changes you introduce, Person must be implemented as an interface.
Student class (implements Person Interface)
Instance variables: studentNumber (int), programName (String), gpa (double). This class will be extended by FulltimeStudent and ParttimeStudent classes. Think about the access specifiers for these instance variables.
Constructor: do you need a no-arg constructor??? Think and decide!
Methods:
- readInfo(): accepts nothing, return nothing. Reads all student information and save them in the instance variables. As you are implementing Person interface, you have access to instance variables of that class. Not permitted to create local variables. In order to read marks, readMarks() method should be called from this method. Include the required annotation also.
- readMarks(): accepts nothing, return nothing. Reads number of courses, and then reads marks of all courses and stores them in a local double array. This method is always called from within the class (private method???) After reading the marks, this method will call calculateGpa().
- calculateGpa(): accepts a double array, returns nothing. This method is always called from within the class (private method???). This method calculates the gpa and stores it in the instance variable gpa. (you can go with a simple calculation to get a score out of 4 - check out the how here and here).
- printInfo(): accepts nothing, returns nothing. This method prints details of a student using formatted output (printf). Include the required annotation also.
FulltimeStudent Class (extends Student class)
Instance Variables: tuitionFees (double)
Methods:
- readInfo(): accepts nothing, returns nothing. Calls readInfo() of the superclass.
Then, this method reads tuition fees.
- printInfo(): accepts nothing, returns nothing. Calls printInfo() of the superclass.
This method then prints the tuition fees.
ParttimeStudent Class (extends Student class)
Instance Variables: courseFeesTotal (double), credits (double)
Methods:
- readInfo(): accepts nothing, returns nothing. Calls readInfo() of the superclass.
Then, this method reads total course fees and credit hours.
- printInfo(): accepts nothing, returns nothing. Calls printInfo() of the superclass. This method then prints the total course fees and credit hours.
University Class
Instance variables: name (String to store the name of the university),
[]students (Student)
(students is an array of Student)
Constructor: Parameterized constructor gets a name that represents the name of the university and a number that represents the number of students in the university. This constructor sets name (the name of the university) and creates the students array.
Methods:
- printTitle(): prints the title and the header row of the output (See output)
- ReadStudentsDetails(): The purpose of this method is to read details of all students (in a loop). For each student, you need to first read the type of the student 1 for full time
or 2 for part time. If the user enters a number other than 1 or 2, a message Wrong student type should be displayed. Once the student type is read correctly, the right student object should be created. (Here, the student object is taking the form of a FulltimeStudent or a ParttimeStudent, based on the type of the student. Polymorphism). Then, readInfo() should be invoked to read details of all students. Based on the type of the student, the right method will be invoked.
- printStudentDetails(): this method has a for loop that calls printInfo() for all students in the students[] array.
UniversitySystemTest class
This is the driver class (test class), which means this class has the main method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started