Write an application in java that models courses, students, and faculty members
ID: 3887110 • Letter: W
Question
Write an application in java that models courses, students, and faculty members in a university.
General Directions
Use proper Java naming conventions.
each class you create will have private instance variables and any necessary getters and setters.
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
public class Address {
private int streetNumber;
private String streetName;
private String city;
private String state;
private String country;
/**
* @param streetNumber
* @param streetName
* @param city
* @param state
* @param country
*/
public Address(int streetNumber, String streetName, String city,
String state, String country) {
this.streetNumber = streetNumber;
this.streetName = streetName;
this.city = city;
this.state = state;
this.country = country;
}
/**
* @return the streetNumber
*/
public int getStreetNumber() {
return streetNumber;
}
/**
* @param streetNumber
* the streetNumber to set
*/
public void setStreetNumber(int streetNumber) {
this.streetNumber = streetNumber;
}
/**
* @return the streetName
*/
public String getStreetName() {
return streetName;
}
/**
* @param streetName
* the streetName to set
*/
public void setStreetName(String streetName) {
this.streetName = streetName;
}
/**
* @return the city
*/
public String getCity() {
return city;
}
/**
* @param city
* the city to set
*/
public void setCity(String city) {
this.city = city;
}
/**
* @return the state
*/
public String getState() {
return state;
}
/**
* @param state
* the state to set
*/
public void setState(String state) {
this.state = state;
}
/**
* @return the country
*/
public String getCountry() {
return country;
}
/**
* @param country
* the country to set
*/
public void setCountry(String country) {
this.country = country;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return " [streetNumber=" + streetNumber + ", streetName=" + streetName
+ ", city=" + city + ", state=" + state + ", country="
+ country + "]";
}
}
package com.school;
public class Person extends Address {
private String name;
public Person(int streetNumber, String streetName, String city,
String state, String country, String name) {
super(streetNumber, streetName, city, state, country);
this.name = name;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Person [name=" + name + ", getStreetNumber()="
+ getStreetNumber() + ", getStreetName()=" + getStreetName()
+ ", getCity()=" + getCity() + ", getState()=" + getState()
+ ", getCountry()=" + getCountry() + ", toString()="
+ super.toString() + ", getClass()=" + getClass()
+ ", hashCode()=" + hashCode() + "]";
}
}
package com.school;
import java.util.ArrayList;
import java.util.List;
public class Student extends Person {
private String CIN;
List<Course> courses;
public Student(int streetNumber, String streetName, String city,
String state, String country, String name, String CIN) {
super(streetNumber, streetName, city, state, country, name);
// TODO Auto-generated constructor stub
this.CIN = CIN;
courses = new ArrayList<Course>();
}
/**
* @return the cIN
*/
public String getCIN() {
return CIN;
}
/**
* @param cIN
* the cIN to set
*/
public void setCIN(String cIN) {
CIN = cIN;
}
public void addCourse(Course c) {
courses.add(c);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Student [CIN=" + CIN + ", courses=" + courses + ", getName()="
+ getName() + ", toString()=" + super.toString()
+ ", getStreetNumber()=" + getStreetNumber()
+ ", getStreetName()=" + getStreetName() + ", getCity()="
+ getCity() + ", getState()=" + getState() + ", getCountry()="
+ getCountry() + ", getClass()=" + getClass() + ", hashCode()="
+ hashCode() + "]";
}
}
package com.school;
public class Course {
String identifier;
String courseTitle;
/**
* @param identifier
* @param courseTitle
*/
public Course(String identifier, String courseTitle) {
this.identifier = identifier;
this.courseTitle = courseTitle;
}
/**
* @return the identifier
*/
public String getIdentifier() {
return identifier;
}
/**
* @param identifier
* the identifier to set
*/
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
/**
* @return the courseTitle
*/
public String getCourseTitle() {
return courseTitle;
}
/**
* @param courseTitle
* the courseTitle to set
*/
public void setCourseTitle(String courseTitle) {
this.courseTitle = courseTitle;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Course [identifier=" + identifier + ", courseTitle="
+ courseTitle + "]";
}
}
package com.school;
import java.util.ArrayList;
import java.util.List;
public class FacultyMember extends Person {
String employeeId;
List<Course> schedule;
/**
* @param streetNumber
* @param streetName
* @param city
* @param state
* @param country
* @param name
* @param employeeId
*/
public FacultyMember(int streetNumber, String streetName, String city,
String state, String country, String name, String employeeId) {
super(streetNumber, streetName, city, state, country, name);
this.employeeId = employeeId;
schedule = new ArrayList<Course>();
}
/**
* @return the employeeId
*/
public String getEmployeeId() {
return employeeId;
}
/**
* @param employeeId
* the employeeId to set
*/
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public void addSchedule(Course c) {
schedule.add(c);
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "FacultyMember [employeeId=" + employeeId + ", schedule="
+ schedule + ", getName()=" + getName() + ", toString()="
+ super.toString() + ", getStreetNumber()=" + getStreetNumber()
+ ", getStreetName()=" + getStreetName() + ", getCity()="
+ getCity() + ", getState()=" + getState() + ", getCountry()="
+ getCountry() + ", getClass()=" + getClass() + ", hashCode()="
+ hashCode() + "]";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.