Introduction to methods: Yearly Calendar: Fall 2024
Learning Objective(s)
- Appreciate the use of methods/abstraction to add clarity to a larger program
- Be able to use arguments to methods
- Understand the difference between void methods and methods that return a value
- Learn to document methods well
- Experience with lot's of details and the need for abstraction
Overview of the Program
Adapt the previous calendar program to use methods to print out a yearly calendar
Specifics
- Same as in lab 6 except it must use the following methods:
- a method to get a valid number (passed high value, low value, message, and a scanner for the keyboard)
- a method to display the year's calendar (sent year and starting day). It can do no output itself.
- a method to display an entire month (sent the year, month, and starting day). The only output it can do itself is a blank line at the end (if needed).
- a method to return the number of days in a month (sent the year and month).
- a method to output the name of the month (sent the month).
- a method to determine if the year is a leap year (sent the year).
- a method to display the leading blanks for a month (sent day the month starts on)
- An additional method to display a sequence of numbers on one line would be beneficial but not required. It would be send the starting and ending number. So if it was sent 2 and 8 it would print: 2 3 4 5 6 7 8.
- The keyboard can only be instantiated one time.
- Suggestion: Take a working solution and slowing add methods. Get the program to work correctly after each method before moving onto another. A good order is
- method to get a valid number
- method to determine if a leap year
- method to output the name of the month
- method to determine the number of days in a month
- method to display leading blanks for a month
- method to display a month (with extra output statements for now → having extra output statements for the displaying of a month will only cost a few points)
- method to display a year
Sample dialogue
Below is a sample dialogue. The prompts may vary but the input given by the user is to be the same format. Your output can vary somewhat as long as the required data is nicely displayed.
What year (between 1700 and 2700)? 2024
What day does the year start on (0-6)? 1
Jan
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
Feb
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
Mar
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
Apr
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
May
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
Jun
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
Jul
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
Aug
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
Sep
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
Oct
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
Nov
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
Dec
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
You can also run a solution for this program if you want. See classroom instructions for more details.
Lab Hints
- Hint 1: a flowchart that you can use: This flowchart is a bit more abstract on purpose. Your programming should be advancing.
- Hint 2: Computing if a year is a leap year: See the Internet
- Hint 3: Use the solution from lab 6 to get started
Submission
- Create a software development report
- For the system design, you may use my flowchart if it is the design of your program. Otherwise, you need to make your own.
- For testing report,
- display complete correct output in your report for at least one year to show what it should look like. You don't need to display the complete output for each test.
- make sure you do statement coverage testing
- at the end of the testing report include a statement about how many different tests would be needed if you did path coverage testing and why that is the number.
- For the improvement section, specify how many points were lost from the last lab that you should not lose points for on this lab because you corrected the problem
- If the solution is used, that should be included in "Outside Resources"
- create a pdf document from your software development report
- create an empty zip folder
- place only Calendar.java and your pdf document into it
- submit the zip folder on canvas
Optional improvements
Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
- Add code to sufficiently test each method. For example: the testing of get number of days in a month might include :
- System.out.println("The number of days in Jan of 2024 should be 31 and it is "+getNumDays(1,2024));
- There would be quite a few of these to just test getNumDays.
- For each method to test, create a 2nd method that completely tests the first method.
- This version should be called CalendarTest.java and should also be placed in the zip folder before submitting.