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 Link icon

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

    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 Link icon

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

    • Quarter Link icon

      public Quarter(int yyyyq)
    • Quarter Link icon

      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 Link icon

    • getValue Link icon

      public int getValue()
    • setValue Link icon

      public void setValue(int yyyyq)
    • getYY Link icon

      public String getYY()
    • getYYYY Link icon

      public String getYYYY()
    • getYYYYQ Link icon

      public String getYYYYQ()
    • toString Link icon

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

      public String getQ()
    • increment Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      public static int qyyToyyyyQ(String qyy)
    • equals Link icon

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

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

      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