FRQ 1
Notes on what I learned for FRQ 1
Explanation of code
Files overview
There are 3 files: APCalendar.java
, Year.java
, and CalendarApiController.java
. APCalendar.java
contains the methods that provide the functions of the calendar, Year.java
is the POJO to get information from the APCalendar
class, and CalendarApiController.java
controls the REST API.
How the code works
Calendar data can be accessed through the URI. The endpoints are specified with @GetMapping
in CalendarApiController.java
. Within each endpoint, a Year
object is created and the setYear
method is called. Within the Year
class, you can see which setters are called. These setters then call methods in the APCalendar
class, which are programmed to output things such as if a given year is a leap year, the day of the week of a day, how many days since January 1st a given day of the year is, etc.
What I learned
Within the APCalendar
class, there were many methods that required multiple parameters, such as dayOfYear
or numberOfLeapYears
. I originally had a little trouble in getting these parameters as input in the endpoint, and after some research, I found that the syntax in the endpoint is something like this: /{var1}/{var2}/{etc}
. Then, to specify multiple PathVariables, simply split them apart with commas, like this: <code>@PathVariable int var, @PathVariable int var2</code>.
Using the debugger
The debugger not only helped me in debugging code; it also helped me to learn how the code works. One thing that I was confused about was what the toString()
method did in Year.java
. By running the debugger on the tester, (as seen below),
I learned that there is a default toString()
method. This is overriden in the Year
class. The System.out.println
automatically calls the toString()
method, which is why an output in JSON format is shown when the tester is run.