Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab b8 Write a program to generate the entire calendar for one year. The program must get two values from the user: (1) the year

image text in transcribed

Lab b8 Write a program to generate the entire calendar for one year. The program must get two values from the user: (1) the year and (2) the day of the week for January 1st of that year. The year, which should be positive, is needed to check for and handle leap years1. The day of the week for January ist is needed so that you know where to start the calendar. The user should enter o for Sunday, 1 for Monday, or 6 for Saturday. As always, you need to validate the user's input. To actually print the calendar, you must use a single method that prints out the calendar for one month and then call this function 12 times from mainO, once for each month in the year. To check for a leap year you will need to write another method that takes the year as a parameter and returns true if it's a leap year, or false otherwise The calendar should be printed in the form below. In this example, January starts on a Saturday (day 6) Note that February starts on a Tuesday in this example because January ended on a Monday anuary 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 February 6 7 8 9 10 11 12 This is a very complex program with many pieces, and there are many different ways to approach it. Before writing any code, take some time to think through the problem. The most difficult piece is to understand how to write a single method that can print out the calendar for any month. Here is a suggestion for how to proceed 1. Try to write the isLeapYear method - this is self-contained Now focus on the printMonth method. Start with printing the name of the month (supplied as a parameter) and trailing new lines. Then try getting the correct number of days printed (also supplied as a parameter) without worrying about which day the month starts on. Then focus on getting the numbers to line up (hint: how are you going to deal with a single digit vs. double digits), then on starting a new line after each Saturday. Now make sure your return value is correct - it should be one day of the week later than the last printed day (with special handling if the last day is Saturday). Finally, print "blank" entries for each day until the first of the month For example, if January 1*t is a Wednesday, you need to print 3 blank entries 2. Next, shift your focus to the main() method. Start by getting input from the user and validating them 3. Now, assuming the inputs are supplied correctly, call your methods to print out each month (i.e 12 calls to printMonth). Note that you will need to use the return value from this method to decide where to start each subsequent month 4. Finally, add correct support for leap years - think about how to use your isLeapYear method to correctly output February 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago

Question

Describe the nature of negative messages.

Answered: 1 week ago