Question: Create University.java to display an array of information about students and faculty at your university. Create an array of 5 students and instructors object to
Create University.java to display an array of information about students and faculty at your university. Create an array of 5 students and instructors object to store multiple instances.
Create a Person class is abstract with a method called personalInterest(). The class stores first name, last name, and email address. Create a class named Student that extends the Person class and overrides the abstract method. This class stores a student id, major, student level (freshman, sophomore, junior, or senior).
Create a University class with the main method.
Example output for the program on inheritance:
List students or instructors: students
OUTPUT: Name: Frank Jones Email: frank44@Jones.com Student id: M10293 Major: Business Level: Sophomore
Name: John Smith Email: john55@Smithl.com Student id: J55294 Major: English Level: Freshman
List students or instructors: instructors
OUTPUT: Name: Anne Price Email: anne@nctc.edu Social security number: 111-11-1111 Subject area: Physics for 3 years.
Name: Kris Moore Email: kmoore@nctc.edu Social security number: 333224444 Subject area: Statistics for 11 years.
---------------------------
Class Layout:
class Person { }
class Student extends Person { }
class Instructor extends Person { }
public class University {
main () {
Student [] student = new Student[5]; Instructor [] instructor = new Instructor[5];
// question: add student or instructor? // create student object and populate the data in the object // create instructor object and populate the data in the object // question: Ask if you want to see the students or the instructors? // Display either the student information or the instructor information } }
*********************************************************
// Person CLASS class Person { private String firstName; private String lastName; private String emailAddress; /** * constructor 1 */ public Person() { // initialize the three class attributes firstName, lastName, emailAddress firstName = ""; lastName = ""; emailAddress = ""; } /** * constructor 2 */ public Person(String emailAddress) { this.firstName = ""; this.lastName = ""; this.emailAddress = emailAddress; } /** * constructor 3 */ public Person(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; this.emailAddress = ""; } /** * constructor 4 */ public Person(String firstName, String lastName, String emailAddress) { // initialize the three class attributes firstName, lastName, emailAddress this.firstName = firstName; this.lastName = lastName; this.emailAddress = emailAddress; }
//Create setters and getters for firstName, lastName, emailAddress public String getFirstName(){return firstName;} public String getLastName(){return lastName;} public String getEmailAddress(){return emailAddress;}
public void setFirstName(String firstName){this.firstName = firstName;} public void setLastName(String lastName) {this.lastName = lastName;} public void setEmailAddress(String emailAddress){this.emailAddress = emailAddress;} } //Instructor class (inner), implemented all required implementations and modifications
class Instructor extends Person{ //Define the Instructor class as a subclass of Person {
private long SSN; private String subject; private long yearsWorked; public Instructor() { this.SSN = 0; this.subject = ""; this.yearsWorked = 0; }
public Instructor(String subject) { //initialize the class attibutes SSN, subject, yearsWorked this.SSN = 0; this.subject = subject; this.yearsWorked = 0; }
public Instructor(long SSN, long yearsWorked) { //initialize the class attibutes SSN, subject, yearsWorked this.SSN = SSN; this.subject = ""; this.yearsWorked = yearsWorked; }
public Instructor(long SSN, String subject, long yearsWorked) { //initialize the class attibutes SSN, subject, yearsWorked this.SSN = SSN; this.subject = subject; this.yearsWorked = yearsWorked; }
//Create setters and getters for SSN, subject, yearsWorked public Long getSSN(){return SSN;} public String getSubject(){return subject;} public Long getYearsWorked(){return yearsWorked;}
public void setSSN(Long SSN){this.SSN = SSN;} public void setSubject(String subject) {this.subject = subject;} public void setYearsWorked(Long yearsWorked){this.yearsWorked = yearsWorked;}
public void addInstructor() { Scanner input = new Scanner(System.in); String userValue = ""; System.out.println("*** INSTRUCTOR INFORMATION ***"); System.out.print("First Name ?:"); userValue = input.nextLine(); setFirstName(userValue); System.out.print("Last Name ?:"); userValue = input.nextLine(); setLastName(userValue); System.out.print("Email Address ?:"); userValue = input.nextLine(); setEmailAddress(userValue); System.out.print("SSN ?:"); this.SSN = input.nextLong(); input.nextLine(); System.out.print("Subject ?:"); this.subject = input.nextLine(); System.out.print("Years Worked ?:"); this.yearsWorked = input.nextLong(); input.nextLine(); }
public void showInstructor() { System.out.println("*** DISPLAY INSTRUCTOR INFORMATION ***"); System.out.println("Name :" + getFirstName() + " " + getLastName()); System.out.println("Email Address :" + getEmailAddress()); System.out.println("Social Security Number :" + this.SSN); System.out.println("Subject Area :" + this.subject + " for " + this.yearsWorked); } }
// Student CLASS class Student extends Person { //Create the Student class as a subclass (child of Person) {
private long studentId; private String major; private String studentLevel;
//Complete the constructor. Initialize the attributes studentID, major, studentLevel public Student() { studentId = 0; major = ""; studentLevel = ""; }
//Complete the overloaded constructor.Initialize the attributes studentID, major, studentLevel public Student(long studentId) { this.studentId = studentId; major = ""; studentLevel = ""; } //Complete the overloaded constructor.Initialize the attributes studentId, major, studentLevel public Student(String major, String studentLevel) { this.studentId = 0; this.major = major; this.studentLevel = studentLevel; } //Complete the overloaded constructor.Initialize the attributes studentId, major, studentLevel public Student(long studentId, String major, String studentLevel) { this.studentId = studentId; this.major = major; this.studentLevel = studentLevel; } //Create setters and getters for studentId, major, studentLevel public Long getStudentId(){return studentId;} public String getMajor(){return major;} public String getStudentLevel(){return studentLevel;}
public void setStudentId(Long studentId){this.studentId = studentId;} public void setMajor(String major) {this.major = major;} public void setStudentLevel(String studentLevel){this.studentLevel = studentLevel;}
public void addStudent() { Scanner input = new Scanner(System.in); String userValue = ""; System.out.println("*** STUDENT INFORMATION ***"); System.out.print("First Name :"); userValue = input.nextLine(); setFirstName(userValue); System.out.print("Last Name :"); userValue = input.nextLine(); setLastName(userValue); System.out.print("Email Address :"); userValue = input.nextLine(); setEmailAddress(userValue); System.out.print("Student Id :"); studentId = input.nextLong(); input.nextLine(); System.out.print("Major :"); this.major = input.nextLine(); System.out.print("Student Level :"); this.studentLevel = input.nextLine(); }
public void showStudent() { System.out.println("*** DISPLAY STUDENT INFORMATION ***"); System.out.println("Name :" + getFirstName() + " " + getLastName()); System.out.println("Email Address :" + getEmailAddress()); System.out.println("Student Id :" + this.studentId); System.out.println("Major :" + this.major); System.out.println("Student Level :" + this.studentLevel); } } // COLLEGE CLASS
public class College { // Create a class attribute called student of type Student // Create a class attribute called instructor of type Instructor private Student student; private Instructor instructor;
public College() {
this.student = new Student(); this.instructor = new Instructor(); }
public College(Student student) { this.student = student; this.instructor = new Instructor(); }
public College(Instructor instructor) { this.student = new Student(); this.instructor = instructor; }
public College(Student student, Instructor instructor) { this.student = student; this.instructor = instructor; }
public College(Instructor instructor, Student student) { this.student = student; this.instructor = instructor; } //Create setters and getters for student and instructor public Student getStudent(){return student;} public Instructor getInstructor(){return instructor;}
public void setStudent(Student student){this.student = student;} public void setInstructor(Instructor instructor) {this.instructor = instructor;} public void addSudent() { student.addStudent(); }
public void addInstructor() { instructor.addInstructor(); }
public void displayStudent() { student.showStudent(); }
public void displayInstructor() { instructor.showInstructor(); } // --------------
/** * *** MAIN LOGIC * * @param args */ public static void main(String[] args) { String flag = ""; String userValue = ""; College Baylor = new College(); Scanner userInput = new Scanner(System.in);
do { System.out.print(" Add student or instructor (s/i)?"); userValue = userInput.nextLine();
if ("s".equalsIgnoreCase(userValue)) { Student student = new Student(); student.addStudent(); Baylor.setStudent(student);
} else if ("i".equalsIgnoreCase(userValue)) { Instructor instructor = new Instructor(); instructor.addInstructor(); Baylor.setInstructor(instructor); } else { System.out.println("ERROR: Invalid Entry"); }
System.out.print(" Display student or instructor (s/i)?"); userValue = userInput.nextLine(); if ("s".equalsIgnoreCase(userValue)) { Baylor.getStudent(); Baylor.displayStudent(); } else if ("i".equalsIgnoreCase(userValue)) { Baylor.getInstructor(); Baylor.displayInstructor(); }
System.out.print(" Would you like to continue or exit(c/x):"); flag = userInput.nextLine(); } while (flag.equalsIgnoreCase("C")); }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
