Class Quarter

java.lang.Object
edu.ucsb.cs156.courses.models.Quarter

public class Quarter extends Object
Represents a UCSB quarter. Allows easy conversion between QYY alphanumeric format (F19, W20, S20, M20) and YYYYQ numerical format (20194, 20201, 20202, 20203) as well as incrementing and decrementing.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Quarter(int yyyyq)
     
    Construct a Quarter object from a string s, either in QYY or YYYYQ format.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Subtract one from current quarter, and return the value of that quarter as an int.
    boolean
     
     
    static String
    getQ(int yyyyq)
    Take yyyyq int format and return single character for quarter, either "W", "S", "M", or "F" for last digit 1, 2, 3, 4, respectively.
    int
     
     
    static String
    getYY(int yyyyq)
    Take yyyyq int format and return two digit year as a String Throw illegal argument exception if not in yyyyq format.
     
    static String
    getYYYY(int yyyyq)
    Take yyyyq int format and return four digit year as a String Throw illegal argument exception if not in yyyyq format.
     
    int
     
    int
    Advance to the next quarter, and return the value of that quarter as an int.
    static List<Quarter>
    quarterList(String start, String end)
    return a list of Quarters starting with the start parameter and ending with the end parameter, inclusive.
    static int
     
    void
    setValue(int yyyyq)
     
     
    static int
    Convert yyyyq as string to int, throwing exception if format is incorrect
    static String
    yyyyqToQyy(int yyyyq)
    Convert yyyyq int format to Yqq String format throwing exception if format is incorrect

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Quarter

      public Quarter(int yyyyq)
    • Quarter

      public Quarter(String s)
      Construct a Quarter object from a string s, either in QYY or YYYYQ format. If s is of length three, QYY format is expected, if 5 then YYYYQ format is expected. Otherwise an IllegalArgumentException is thrown.
      Parameters:
      s - Quarter either in QYY or YYYYQ format
  • Method Details

    • getValue

      public int getValue()
    • setValue

      public void setValue(int yyyyq)
    • getYY

      public String getYY()
    • getYYYY

      public String getYYYY()
    • getYYYYQ

      public String getYYYYQ()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getQ

      public String getQ()
    • increment

      public int increment()
      Advance to the next quarter, and return the value of that quarter as an int.
      Returns:
      the new getValue() for the quarter, i.e. quarter as in in yyyyq format
    • decrement

      public int decrement()
      Subtract one from current quarter, and return the value of that quarter as an int.
      Returns:
      the new getValue() for the quarter, i.e. quarter as in in yyyyq format
    • yyyyqToInt

      public static int yyyyqToInt(String yyyyq)
      Convert yyyyq as string to int, throwing exception if format is incorrect
      Parameters:
      yyyyq - String in yyyyq format (e.g. 20194 for F19 (Fall 2019))
      Returns:
      int representation of quarter
      Throws:
      IllegalArgumentException
    • yyyyqToQyy

      public static String yyyyqToQyy(int yyyyq)
      Convert yyyyq int format to Yqq String format throwing exception if format is incorrect
      Parameters:
      yyyyq - int (e.g. 20194 for Fall 2019
      Returns:
      Qyy representation (e.g. F19)
      Throws:
      IllegalArgumentException
    • getQ

      public static String getQ(int yyyyq)
      Take yyyyq int format and return single character for quarter, either "W", "S", "M", or "F" for last digit 1, 2, 3, 4, respectively. Throw illegal argument exception if not in yyyyq format.
      Parameters:
      yyyyq - int (e.g. 20194 for Fall 2019)
      Returns:
      single char string for quarter (e.g. "F")
      Throws:
      IllegalArgumentException
    • getYY

      public static String getYY(int yyyyq)
      Take yyyyq int format and return two digit year as a String Throw illegal argument exception if not in yyyyq format.
      Parameters:
      yyyyq - int (e.g. 20194 for Fall 2019)
      Returns:
      two char string for year (e.g. "19")
      Throws:
      IllegalArgumentException
    • getYYYY

      public static String getYYYY(int yyyyq)
      Take yyyyq int format and return four digit year as a String Throw illegal argument exception if not in yyyyq format.
      Parameters:
      yyyyq - int (e.g. 20194 for Fall 2019)
      Returns:
      four char string for year (e.g. "2019")
      Throws:
      IllegalArgumentException
    • qyyToyyyyQ

      public static int qyyToyyyyQ(String qyy)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • quarterList

      public static List<Quarter> quarterList(String start, String end)
      return a list of Quarters starting with the start parameter and ending with the end parameter, inclusive. The result will automatically go in chronological or reverse chronological order, depending on the order of the parameters.
      Parameters:
      start -
      end -
      Returns:
      list of quarters in specified order