Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.missouriwestern.cpozo.csc254.sqlwork;
- import java.util.Objects;
- public class Section implements Comparable<Section> {
- String discipline;
- String number;
- String crn;
- String title;
- String instructor;
- Integer maxEnrollment;
- Integer seatsAvailable;
- //Constructors
- public Section(String crn, String discipline, String number, String title, String instructor, Integer maxEnrollment, Integer seatsAvailable){
- setCrn(crn);
- setDiscipline(discipline);
- setNumber(number);
- setTitle(title);
- setInstructor(instructor);
- setMaxEnrollment(maxEnrollment);
- setSeatsAvailable(seatsAvailable);
- }
- public Section(String courseID, String crn, String title, String instructor, Integer maxEnrollment, Integer seatsAvailable){
- splitCourseId(courseID);
- setCrn(crn);
- setTitle(title);
- setInstructor(instructor);
- setMaxEnrollment(maxEnrollment);
- setSeatsAvailable(seatsAvailable);
- }
- private void splitCourseId(String courseId) {
- if (courseId.length() >= 6) {
- this.discipline = courseId.substring(0, 3);
- this.number = courseId.substring(3, 6);
- }
- }
- public boolean isOpen(){
- boolean open=seatsAvailable>0?true:false;
- return open;
- }
- public int compareTo(Section other) {
- if (other !=null) {
- String courseID = getCourseID();
- String othercourseID = other.getCourseID();
- int result = 0;
- result = courseID.compareTo(othercourseID);
- if (result == 0)
- result = this.crn.compareTo(other.crn);
- return result;
- }
- return 1;
- }
- public String toString() {
- String classStatus=isOpen() == true ? "Open" : "Full";
- String Result = String.format("%s %s%s (%s) \"%s\" %o enrolled (Max:%o) Instructor: %s ",classStatus,discipline, number, crn, title, seatsAvailable, maxEnrollment, instructor);
- return Result;
- }
- //Setters
- public void setDiscipline(String discipline) {
- this.discipline = discipline.toUpperCase();
- }
- public void setNumber(String number) {
- this.number = number;
- }
- public void setCrn(String crn) {
- this.crn = crn;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public void setInstructor(String instructor) {
- this.instructor = instructor;
- }
- public void setMaxEnrollment(Integer maxEnrollment) {
- this.maxEnrollment = maxEnrollment;
- }
- public void setSeatsAvailable(Integer seatsAvailable) {
- this.seatsAvailable = seatsAvailable;
- }
- //Getters
- public String getDiscipline() {
- return discipline;
- }
- public String getNumber() {
- return number;
- }
- public String getCrn() {
- return crn;
- }
- public String getTitle() {
- return title;
- }
- public String getInstructor() {
- return instructor;
- }
- public Integer getMaxEnrollment() {
- return maxEnrollment;
- }
- public Integer getSeatsAvailable() {
- return seatsAvailable;
- }
- public String getCourseID(){
- return discipline+number;
- }
- public Integer getEnrolled(){
- return maxEnrollment-seatsAvailable;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment