Note: The link to this repository must be turned in no later than the end of the week on Friday, November 7 @ 11:59 p.m.
A calendar application that:
- Asks the user for a year and a month
- Prints a formatted calendar for that month
Example Output:
Enter full year (e.g., 2012): 2025
Enter month as a number between 1 and 12: 11
November 2025
-----------------------------
Sun Mon Tue Wed Thu Fri Sat
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
By the end of this activity, you'll understand:
- Method Abstraction: Breaking complex problems into smaller, manageable pieces
- Stepwise Refinement: Top-down design and bottom-up implementation
- Code Reusability: Writing methods that can be used multiple times
- Modular Programming: Making code easier to read, debug, and test
Print a calendar for a given month and year
- Get input from the user (year and month)
- Print the calendar for that month
The printMonth method needs to:
- Print the month title (month name, year, and day headers)
- Print the month body (the actual dates)
- Get the month name (convert number to string like "November")
- Get the start day of the week (is the 1st a Sunday? Monday?)
- Get the number of days in the month (28, 29, 30, or 31?)
- Calculate the total number of days since a known reference date
- Determine if a year is a leap year
- Get the number of days in each month
We'll build from the bottom up, starting with the smallest helper methods and working our way up to the main program.
- ✅ isLeapYear - The foundation (we did this in Chapter 3!)
- ✅ getNumberOfDaysInMonth - Uses isLeapYear
- ✅ getTotalNumberOfDays - Uses the above two methods
- ✅ getStartDay - Uses getTotalNumberOfDays
- ✅ getMonthName - Converts month number to name
- ✅ printMonthTitle - Uses getMonthName
- ✅ printMonthBody - Uses getStartDay and getNumberOfDaysInMonth
- ✅ printMonth - Uses printMonthTitle and printMonthBody
- ✅ main - Puts it all together!
- January 1, 1800 was a Wednesday (day 3 of the week, where Sunday = 0)
- We calculate all dates relative to this known point
- 31 days: January, March, May, July, August, October, December
- 30 days: April, June, September, November
- 28/29 days: February (depends on leap year)
A year is a leap year if:
- It's divisible by 400, OR
- It's divisible by 4 AND NOT divisible by 100
Examples:
- 2000 = leap year (divisible by 400)
- 2024 = leap year (divisible by 4, not by 100)
- 1900 = NOT a leap year (divisible by 100, but not 400)
- Open the file
F25_PrintCalendar_FirstName_LastName.java - Replace
FirstName_LastNamewith your actual name - Follow along with the instructor or video
- Complete each
TODOsection as we work through it together - Test your program frequently!
After completing each method, you can test it by:
- Uncommenting the test code in
main - Running the program
- Verifying the output matches expected results
- Work step-by-step: Don't try to write everything at once
- Test frequently: After writing each method, test it!
- Use the textbook: This follows the example exactly
- Ask questions: If you're stuck, raise your hand or ask in chat
- Collaborate: Discuss with classmates, but write your own code
- Think about reusability: Notice how we use smaller methods in bigger ones
- Each method has ONE clear purpose
- Easy to read and understand
- Methods like
isLeapYearandgetNumberOfDaysInMonthare used multiple times - No redundant code!
- Test one method at a time
- If something breaks, you know exactly where to look
- Different programmers could work on different methods
- As long as the method signatures match, everything works together
- Textbook: Chapter 6 - Methods
- Lecture slides (provided in class)
- Previous class video recording
- Java API Documentation: Scanner
Remember: Programming is a skill that improves with practice. Work through this carefully, and you'll understand how professional programmers break down complex problems into manageable pieces! 🌟