Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application that models courses, students, and faculty members in a uni

ID: 3887364 • Letter: W

Question

Write an application that models courses, students, and faculty members in a university.

General Directions

Use proper Java naming conventions.

From now on it will be assumed that each class you create will have private instance variables and any necessary getters and setters. I will no longer explictly ask you to create these.

Be sure to implement toString() for each class.

You may use either Scanners and System.out.println or JOptionPane for the I/O in this lab. Either way, think carefully about how to organize the input/output for this lab *before* you begin coding.

Address Class

An address has a street number, street name, city, state or province, and country.

Person Class

A Person has a name and an Address (represented by an object of class Address, not a String). Note that the subclasses of Person inherit the fields and methods of Person. You may need to override some of the methods in the subclasses.

Student Class

Student is a subclass of Person. In addition to the data inherited from Person, a student has CIN and a course schedule represented by an ArrayList of Courses (objects of class Course). You must provide ways for a Student to add and drop an existing Course.

FacultyMember Class

FacultyMember is also subclass of Person. A FacultyMember has an employee id number and a teaching schedule, which is an ArrayList of Courses. Provide a way to assign a FacultyMember to teach an existing Course and for a Faculty member to find a class in the list and drop it.

Course Class

A course has a course identifier (eg, EE-132) and a number of units (int).

University Class

Write a University class that maintains lists of Students, Courses, and FacultyMembers and has an instance method containing a menu that provides ways to list them and to create them and add them to the list. Provide ways to delete Students and FacultyMembers and for Students and FacultyMembers to add and delete Courses from their course schedules. However, you do not need to provide a way to delete a Course from the list of Courses. Do not create a new Course when a Student adds or when a faculty member is assigned to teach; let the user choose a Course from the list.

Driver Class

Write a simple Driver class that instantiates a University and calls the correct method to get the menu.

Explanation / Answer

Hi,

Please see below the classes:

Address.java

public class Address {

private String streetNo;

private String streetName;

private String city;

private String state;

private String province;

private String country;

//Constructor

public Address(String streetNo, String streetName, String city,

String state, String province, String country) {

super();

this.streetNo = streetNo;

this.streetName = streetName;

this.city = city;

this.state = state;

this.province = province;

this.country = country;

}

//Getters and Setter

public String getStreetNo() {

return streetNo;

}

public void setStreetNo(String streetNo) {

this.streetNo = streetNo;

}

public String getStreetName() {

return streetName;

}

public void setStreetName(String streetName) {

this.streetName = streetName;

}

public String getCity() {

return city;

}

public void setCity(String city) {

this.city = city;

}

public String getState() {

return state;

}

public void setState(String state) {

this.state = state;

}

public String getProvince() {

return province;

}

public void setProvince(String province) {

this.province = province;

}

public String getCountry() {

return country;

}

public void setCountry(String country) {

this.country = country;

}

@Override

public String toString() {

return "Address [streetNo=" + streetNo + ", streetName=" + streetName

+ ", city=" + city + ", state=" + state + ", province="

+ province + ", country=" + country + "]";

}

}

Person.java

public class Person

{

protected String name;

protected Address address;

//Constructor

public Person(String name,Address address)

{

this.name = name;

this.address = address;

}

//Getters and Setter

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public Address getAddress()

{

return address;

}

public void setAddress(Address address)

{

this.address = address;

}

@Override

public String toString() {

return "Person [name=" + name + ", address=" + address + "]";

}

}

Student.java

import java.util.ArrayList;

import com.sun.jndi.url.corbaname.corbanameURLContextFactory;

public class Student extends Person

{

private int CIN;

private ArrayList<Course> courseList;

//Constructor

public Student(String name, Address address, int cIN) {

super(name, address);

CIN = cIN;

this.courseList = new ArrayList<Course>();

}

/**

* To add course to courseList

* @param course

*/

public void addCourse(Course course){

if(!isCoursePresent(course.getCourseId())){

this.courseList.add(course);

System.out.println("Course # "+course.getCourseId()+" added to Student courselist.");

}

}

/**

* To remove course to courseList

* @param course

*/

public void removeCourse(String courseId){

for(Course course: courseList){

if(courseId.equalsIgnoreCase(course.getCourseId())){

courseList.remove(course);

System.out.println("Course # "+courseId+" removed from Student courselist.");

break;

}

}

}

/**

* To check if course already present in the list

* @param courseId

* @return

*/

public boolean isCoursePresent(String courseId){

boolean isPresent =false;

for(Course course: courseList){

if(courseId.equalsIgnoreCase(course.getCourseId())){

isPresent = true;

break;

}

}

return isPresent;

}

//Getters and Setter

public int getCIN() {

return CIN;

}

public void setCIN(int cIN) {

CIN = cIN;

}

public ArrayList<Course> getCourseList() {

return courseList;

}

public void setCourseList(ArrayList<Course> courseList) {

this.courseList = courseList;

}

@Override

public String toString() {

return "Student [CIN=" + CIN + ", courseList=" + courseList + "]";

}

}

Course.java

public class Course {

private String courseId;

private int noOfUnits;

//Constructor

public Course(String courseId, int noOfUnits) {

super();

this.courseId = courseId;

this.noOfUnits = noOfUnits;

}

//Getters and Setter

public String getCourseId() {

return courseId;

}

public void setCourseId(String courseId) {

this.courseId = courseId;

}

public int getNoOfUnits() {

return noOfUnits;

}

public void setNoOfUnits(int noOfUnits) {

this.noOfUnits = noOfUnits;

}

@Override

public String toString() {

return "Course [courseId=" + courseId + ", noOfUnits=" + noOfUnits

+ "]";

}

}

FacultyMember.java

import java.util.ArrayList;

public class FacultyMember extends Person{

private String empId;

private ArrayList<Course> teachingSchedule;

//Constructor

public FacultyMember(String name, Address address, String empId) {

super(name, address);

this.empId = empId;

this.teachingSchedule = new ArrayList<Course>();

}

/**

* To teach a new course to teachingSchedule

* @param course

*/

public void teachCourse(Course course){

if(!isCoursePresent(course.getCourseId())){

this.teachingSchedule.add(course);

System.out.println("Course # "+course.getCourseId()+" added to teachingSchedule.");

}

}

/**

* To drop course from teachingSchedule

* @param course

*/

public void removeCourse(String courseId){

for(Course course: teachingSchedule){

if(courseId.equalsIgnoreCase(course.getCourseId())){

teachingSchedule.remove(course);

System.out.println("Course # "+courseId+" removed from teachingSchedule.");

break;

}

}

}

/**

* To check if course already present in the list

* @param courseId

* @return

*/

public boolean isCoursePresent(String courseId){

boolean isPresent =false;

for(Course course: teachingSchedule){

if(courseId.equalsIgnoreCase(course.getCourseId())){

isPresent = true;

break;

}

}

return isPresent;

}

//Getters and Setter

public String getEmpId() {

return empId;

}

public void setEmpId(String empId) {

this.empId = empId;

}

public ArrayList<Course> getTeachingSchedule() {

return teachingSchedule;

}

public void setTeachingSchedule(ArrayList<Course> teachingSchedule) {

this.teachingSchedule = teachingSchedule;

}

@Override

public String toString() {

return "FacultyMember [empId=" + empId + ", teachingSchedule="

+ teachingSchedule + "]";

}

}

University.java

import java.util.ArrayList;

import java.util.Scanner;

public class University {

private ArrayList<Student> studentList = new ArrayList<Student>();

private ArrayList<Course> courseList = new ArrayList<Course>();

private ArrayList<FacultyMember> facultyList = new ArrayList<FacultyMember>();

Scanner scan = new Scanner(System.in);

public void menu(){

String choice = "";

while(!"Q".equalsIgnoreCase(choice)){

System.out.println();

System.out.print("1.List ");

System.out.print("2.Add Course ");

System.out.print("3.Add Student ");

System.out.print("4.Delete Student ");

System.out.print("5.Add Course to Student ");

System.out.print("6.Remove Course for Student ");

System.out.print("7.Add Faculty ");

System.out.print("8.Delete Faculty ");

System.out.print("9.Assign Course to Faculty ");

System.out.print("10.Remove Course for Faculty ");

System.out.print("Q to quit");

System.out.println();

choice= scan.nextLine();

if("1".equalsIgnoreCase(choice)){

display();

}

else if("2".equalsIgnoreCase(choice)){

System.out.println("Enter courseId: ");

String courseId = scan.nextLine();

System.out.println("Enter no Of Units: ");

int units = Integer.valueOf(scan.nextLine());

Course course = new Course(courseId, units);

courseList.add(course);

System.out.println("Course Added to university");

}

else if("3".equalsIgnoreCase(choice)){

System.out.println("Name :");

String name = scan.nextLine();

System.out.println("CIN:");

int CIN =Integer.valueOf(scan.nextLine());

System.out.println("Address - streetNO:");

String streetNo = scan.nextLine();

System.out.println("Street Name :");

String streetName = scan.nextLine();

System.out.println("City:");

String city = scan.nextLine();

System.out.println("State:");

String state = scan.nextLine();;

System.out.println("province:");

String province = scan.nextLine();

System.out.println("country:");

String country = scan.nextLine();;

Address addr = new Address(streetNo, streetName, city, state, province, country);

Student st = new Student(name, addr, CIN);

this.studentList.add(st);

System.out.println("Student Added to university");

}

else if("4".equalsIgnoreCase(choice)){

System.out.println("Enter CIN to delete");

int cin = Integer.valueOf(scan.nextLine());

for(Student student: studentList){

if(cin == student.getCIN()){

studentList.remove(student);

System.out.println("Student # "+cin+" deleted from university.");

break;

}

}

}

else if("5".equalsIgnoreCase(choice)){

String courseId = "";

System.out.println("Enter the student CIN: ");

int cin = Integer.valueOf(scan.nextLine());

for(Student student: studentList){

if(cin == student.getCIN()){

System.out.println("Enter the course Id to add: ");

courseId = scan.nextLine();

for(Course course: courseList){

if(courseId.equalsIgnoreCase(course.getCourseId())){

student.addCourse(course);

}

}

}

}

}

else if("6".equalsIgnoreCase(choice)){

String courseId = "";

System.out.println("Enter the student CIN: ");

int cin = Integer.valueOf(scan.nextLine());

for(Student student: studentList){

if(cin == student.getCIN()){

System.out.println("Enter the course Id to remove: ");

courseId = scan.nextLine();

student.removeCourse(courseId);

}

}

}

else if("7".equalsIgnoreCase(choice)){

System.out.println("Enter name :");

String name = scan.nextLine();

System.out.println("EmpId:");

String empId = scan.nextLine();

System.out.println("Address - streetNO:");

String streetNo = scan.nextLine();

System.out.println("Street Name :");

String streetName = scan.nextLine();

System.out.println("City:");

String city = scan.nextLine();

System.out.println("State:");

String state = scan.nextLine();;

System.out.println("province:");

String province = scan.nextLine();

System.out.println("country:");

String country = scan.nextLine();

System.out.println();

Address addr = new Address(streetNo, streetName, city, state, province, country);

FacultyMember faculty = new FacultyMember(name, addr, empId);

this.facultyList.add(faculty);

System.out.println("Faculty Added to university");

}

else if("8".equalsIgnoreCase(choice)){

System.out.println("Enter EmpID to delete");

String empId = scan.nextLine();

for(FacultyMember faculty: facultyList){

if(empId.equalsIgnoreCase(faculty.getEmpId())){

facultyList.remove(faculty);

System.out.println("Faculty # "+empId+" deleted from university.");

break;

}

}

}

else if("9".equalsIgnoreCase(choice)){

String courseId = "";

System.out.println("Enter the empId ");

String empId = scan.nextLine();

for(FacultyMember faculty: facultyList){

if(empId.equalsIgnoreCase(faculty.getEmpId())){

System.out.println("Enter the course Id to add: ");

courseId = scan.nextLine();

for(Course course: courseList){

if(courseId.equalsIgnoreCase(course.getCourseId())){

faculty.teachCourse(course);

}

}

}

}

}

else if("10".equalsIgnoreCase(choice)){

String courseId = "";

System.out.println("Enter the empId ");

String empId = scan.nextLine();

for(FacultyMember faculty: facultyList){

if(empId.equalsIgnoreCase(faculty.getEmpId())){

System.out.println("Enter the course Id to remove: ");

courseId = scan.nextLine();

faculty.removeCourse(courseId);

}

}

}

}

}

/**

* To display the list

*/

public void display(){

System.out.println("Students: ");

if(studentList.size()>0){

for(Student student: studentList){

System.out.println(student);

}

}

else{

System.out.println("No Students found!");

}

System.out.println("Courses: ");

if(courseList.size()>0){

for(Course course: courseList){

System.out.println(course);

}

}

else{

System.out.println("No Courses found!");

}

System.out.println("Faculty: ");

if(facultyList.size()>0){

for(FacultyMember faculty: facultyList){

System.out.println(faculty);

}

}

else{

System.out.println("No Faculty found!");

}

}

}

Driver.java

public class Driver {

/**

* @param args

*/

public static void main(String[] args) {

University university = new University();

university.menu();

}

}

Sample output:


1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
1
Students:
No Students found!
Courses:
No Courses found!
Faculty:
No Faculty found!

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
2
Enter courseId:
C1
Enter no Of Units:
15
Course Added to university

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
2
Enter courseId:
C2
Enter no Of Units:
20
Course Added to university

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
3
Name :
S1
CIN:
11
Address - streetNO:
d
Street Name :
d
City:
d
State:
d
province:
d
country:
d
Student Added to university

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
3
Name :
S2
CIN:
22
Address - streetNO:
g
Street Name :
g
City:
g
State:
g
province:
g
country:
g
Student Added to university

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
7
Enter name :
F1
EmpId:
1234
Address - streetNO:
h
Street Name :
h
City:
h
State:
h
province:
h
country:
h

Faculty Added to university

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
7
Enter name :
F2
EmpId:
3456
Address - streetNO:
t
Street Name :
t
City:
t
State:
g
province:

country:
g

Faculty Added to university

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
1
Students:
Student [CIN=11, courseList=[]]
Student [CIN=22, courseList=[]]
Courses:
Course [courseId=C1, noOfUnits=15]
Course [courseId=C2, noOfUnits=20]
Faculty:
FacultyMember [empId=1234, teachingSchedule=[]]
FacultyMember [empId=3456, teachingSchedule=[]]

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
5
Enter the student CIN:
11
Enter the course Id to add:
C1
Course # C1 added to Student courselist.

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
9
Enter the empId
3456
Enter the course Id to add:
C2
Course # C2 added to teachingSchedule.

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit
1
Students:
Student [CIN=11, courseList=[Course [courseId=C1, noOfUnits=15]]]
Student [CIN=22, courseList=[]]
Courses:
Course [courseId=C1, noOfUnits=15]
Course [courseId=C2, noOfUnits=20]
Faculty:
FacultyMember [empId=1234, teachingSchedule=[]]
FacultyMember [empId=3456, teachingSchedule=[Course [courseId=C2, noOfUnits=20]]]

1.List 2.Add Course 3.Add Student 4.Delete Student 5.Add Course to Student 6.Remove Course for Student 7.Add Faculty 8.Delete Faculty 9.Assign Course to Faculty 10.Remove Course for Faculty Q to quit

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote