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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionintSubtract one from current quarter, and return the value of that quarter as an int.booleangetQ()static StringgetQ(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.intgetValue()getYY()static StringgetYY(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 StringgetYYYY(int yyyyq) Take yyyyq int format and return four digit year as a String Throw illegal argument exception if not in yyyyq format.getYYYYQ()inthashCode()intAdvance 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 intqyyToyyyyQ(String qyy) voidsetValue(int yyyyq) toString()static intyyyyqToInt(String yyyyq) Convert yyyyq as string to int, throwing exception if format is incorrectstatic StringyyyyqToQyy(int yyyyq) Convert yyyyq int format to Yqq String format throwing exception if format is incorrect
- 
Constructor Details- 
Quarterpublic Quarter(int yyyyq) 
- 
QuarterConstruct 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- 
getValuepublic int getValue()
- 
setValuepublic void setValue(int yyyyq) 
- 
getYY
- 
getYYYY
- 
getYYYYQ
- 
toString
- 
getQ
- 
incrementpublic 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
 
- 
decrementpublic 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
 
- 
yyyyqToIntConvert 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
 
- 
yyyyqToQyyConvert 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
 
- 
getQTake 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
 
- 
getYYTake 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
 
- 
getYYYYTake 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
- 
hashCodepublic int hashCode()
- 
quarterListreturn 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
 
 
-