Package edu.ucsb.cs156.courses.models
Class Quarter
java.lang.Object
edu.ucsb.cs156.courses.models.Quarter
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
-
Method Summary
Modifier and TypeMethodDescriptionint
Subtract one from current quarter, and return the value of that quarter as an int.boolean
getQ()
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
getValue()
getYY()
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.getYYYY()
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.getYYYYQ()
int
hashCode()
int
Advance to the next quarter, and return the value of that quarter as an int.quarterList
(String start, String end) return a list of Quarters starting with the start parameter and ending with the end parameter, inclusive.static int
qyyToyyyyQ
(String qyy) void
setValue
(int yyyyq) toString()
static int
yyyyqToInt
(String yyyyq) Convert yyyyq as string to int, throwing exception if format is incorrectstatic String
yyyyqToQyy
(int yyyyq) Convert yyyyq int format to Yqq String format throwing exception if format is incorrect
-
Constructor Details
-
Quarter
public Quarter(int yyyyq) -
Quarter
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
-
getYYYY
-
getYYYYQ
-
toString
-
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
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
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
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
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
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
-
equals
-
hashCode
public int hashCode() -
quarterList
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
-