Luninariel

Section Class

Nov 1st, 2018
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.43 KB | None | 0 0
  1. package edu.missouriwestern.cpozo.csc254.sqlwork;
  2.  
  3.  
  4. import java.util.Objects;
  5.  
  6. public class Section implements Comparable<Section> {
  7.     String discipline;
  8.     String number;
  9.     String crn;
  10.     String title;
  11.     String instructor;
  12.     Integer maxEnrollment;
  13.     Integer seatsAvailable;
  14.  
  15.     //Constructors
  16.     public Section(String crn, String discipline, String number, String title, String instructor, Integer maxEnrollment, Integer seatsAvailable){
  17.         setCrn(crn);
  18.         setDiscipline(discipline);
  19.         setNumber(number);
  20.         setTitle(title);
  21.         setInstructor(instructor);
  22.         setMaxEnrollment(maxEnrollment);
  23.         setSeatsAvailable(seatsAvailable);
  24.     }
  25.     public Section(String courseID, String crn, String title, String instructor, Integer maxEnrollment, Integer seatsAvailable){
  26.        splitCourseId(courseID);
  27.         setCrn(crn);
  28.         setTitle(title);
  29.         setInstructor(instructor);
  30.         setMaxEnrollment(maxEnrollment);
  31.         setSeatsAvailable(seatsAvailable);
  32.  
  33.     }
  34.     private void splitCourseId(String courseId) {
  35.         if (courseId.length() >= 6) {
  36.             this.discipline = courseId.substring(0, 3);
  37.             this.number = courseId.substring(3, 6);
  38.         }
  39.     }
  40.  
  41.     public boolean isOpen(){
  42.         boolean open=seatsAvailable>0?true:false;
  43.         return open;
  44.     }
  45.  
  46.     public int compareTo(Section other) {
  47.         if (other !=null) {
  48.             String courseID = getCourseID();
  49.             String othercourseID = other.getCourseID();
  50.  
  51.             int result = 0;
  52.             result = courseID.compareTo(othercourseID);
  53.             if (result == 0)
  54.                 result = this.crn.compareTo(other.crn);
  55.             return result;
  56.         }
  57.         return 1;
  58.     }
  59.    
  60.     public String toString() {
  61.  
  62.  
  63.         String classStatus=isOpen() == true ? "Open" : "Full";
  64.  
  65.  
  66.         String Result = String.format("%s %s%s (%s) \"%s\" %o enrolled (Max:%o) Instructor: %s ",classStatus,discipline, number, crn, title, seatsAvailable, maxEnrollment, instructor);
  67.  
  68.  
  69.  
  70.         return Result;
  71.     }
  72.  
  73.     //Setters
  74.  
  75.     public void setDiscipline(String discipline) {
  76.         this.discipline = discipline.toUpperCase();
  77.     }
  78.  
  79.     public void setNumber(String number) {
  80.         this.number = number;
  81.     }
  82.  
  83.     public void setCrn(String crn) {
  84.         this.crn = crn;
  85.     }
  86.  
  87.     public void setTitle(String title) {
  88.         this.title = title;
  89.     }
  90.  
  91.     public void setInstructor(String instructor) {
  92.         this.instructor = instructor;
  93.     }
  94.  
  95.     public void setMaxEnrollment(Integer maxEnrollment) {
  96.         this.maxEnrollment = maxEnrollment;
  97.     }
  98.  
  99.     public void setSeatsAvailable(Integer seatsAvailable) {
  100.         this.seatsAvailable = seatsAvailable;
  101.     }
  102.  
  103.     //Getters
  104.     public String getDiscipline() {
  105.         return discipline;
  106.     }
  107.  
  108.     public String getNumber() {
  109.         return number;
  110.     }
  111.  
  112.     public String getCrn() {
  113.         return crn;
  114.     }
  115.  
  116.     public String getTitle() {
  117.         return title;
  118.     }
  119.  
  120.     public String getInstructor() {
  121.         return instructor;
  122.     }
  123.  
  124.     public Integer getMaxEnrollment() {
  125.         return maxEnrollment;
  126.     }
  127.  
  128.     public Integer getSeatsAvailable() {
  129.         return seatsAvailable;
  130.     }
  131.     public String getCourseID(){
  132.  
  133.         return discipline+number;
  134.     }
  135.     public Integer getEnrolled(){
  136.         return maxEnrollment-seatsAvailable;
  137.     }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment