generated from nighthawkcoders/spring_portfolio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Year.java
50 lines (43 loc) · 1.4 KB
/
Year.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.nighthawk.spring_portfolio.mvc.calendar;
/** Simple POJO
* Used to Interface with APCalendar
* The toString method(s) prepares object for JSON serialization
* Note... this is NOT an entity, just an abstraction
*/
class Year {
private int year;
private boolean isLeapYear;
// zero argument constructor
public Year() {}
/* year getter/setters */
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
this.setIsLeapYear(year);
}
/* isLeapYear getter/setters */
public boolean getIsLeapYear(int year) {
return APCalendar.isLeapYear(year);
}
private void setIsLeapYear(int year) { // this is private to avoid tampering
this.isLeapYear = APCalendar.isLeapYear(year);
}
/* isLeapYearToString formatted to be mapped to JSON */
public String isLeapYearToString(){
return ( "{ \"year\": " +this.year+ ", " + "\"isLeapYear\": " +this.isLeapYear+ " }" );
}
/* standard toString placeholder until class is extended */
public String toString() {
return isLeapYearToString();
}
public static void main(String[] args) {
Year year = new Year();
year.setYear(2022);
System.out.println(year);
}
public String firstDayOfYearToString(int year){
return "{ \"year\": " +year+ ", " + "\"firstDayOfYear\": " + APCalendar.firstDayOfYear(year) + " }";
}
}