Methods: A month's calendar a better way: Spring 2024

06 Feb 2024 - 16:26 | Version 1 |

Learning Objective(s)

  1. Learn about methods
  2. Understand some benefits of abstraction

Overview of the Program

For this lab you adapt the previous program that displays the calendar of a month to use methods

Specifics

  • The program should be called DisplayMonthMethod
  • Input should be the year, followed by the month, and then the day it starts on (with Sunday being 0 and Saturday being 6). Only valid values should be allowed. The year can range from 1500 to 5000
  • The name of the month should be displayed first (you may choose the language)
  • You must account for leap year. Note: leap year is not a simple as every four leaps. Research the details.
  • The month days should line up nicely.
  • You should have the following methods:
    • getValid: This is sent a low value, a high value, a message, and the keyboard. It returns an integer within that range. It continues to get an integer from the user (displaying the message each time until it is give a proper value)
    • displayMonth: This method is sent the year, month, and starting day. It does not return a value but is responsible to see that the entire month is properly displayed. It should have NO print or println statements itself. It can only have one selection statement at that should be in its one loop.
    • getNumDays: This method is sent a year and a month and returns the number of days in that month.
    • displayMonthTitle: This method is sent a month and outputs it title (i.e. May if sent 5)
    • displaySpaces: This method is sent an integer and outputs 3 times that many spaces on one line. It does NOT output a new line.

    • optional displayWeek: This method is sent a number representing the first and last days of the week. It does not return anything. It displays those days on a line and outputs the new line at the end. This method is optional. However it is HIGHLY recommended that you write it and use it.

Sample dialogue

Below is a sample dialogue. Your output can vary somewhat as long as the required data is nicely displayed
What is the year, month and day of the week?
2023 09 05
September
                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 
You can also run a solution for this program if you want. See classroom instructions for more details.

Submission

  1. Create your SDR.
    • In Lessons Learned, include a discussion on how the methods contributed to abstraction and the readability of the code.
    • Your testing should include at least 2 different types of errors and ensure that every line of code is executed at least once and there is a least one month for each starting day. The actual start day does not have to be accurate (unless you are doing the extra credit)
    • If you used any hints, be sure to indicate that in the Outside Resources Used section
  2. Convert your SDR into a pdf document
  3. Create an empty zip folder
  4. Place your java file and pdf document in it.
  5. Submit the zip folder on canvas

Hints

  1. Algorithm hint

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.
  1. Compute the first day of the month. This must be a separate method
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine