Question

Write a C# program that prints a calendar for a given year. Call this program calendar....

Write a C# program that prints a calendar for a given year. Call this program calendar.

This program needs to use Switch Case in order to call the methods and format to print each month.

The program prompts the user for two inputs:

      1) The year for which you are generating the calendar.
      2) The day of the week that January first is on, you will use the following notation to set the day of the week:

     

      0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday
      4 Thursday                 5 Friday                      6 Saturday

Your program should generate a calendar similar to the one shown in the example output below. The calendar should be printed on the screen. Your program should be able to handle leap years. A leap year is a year in which we have 366 days. That extra day comes at the end of February. Thus, a leap year has 366 days with 29 days in February. A century year is a leap year if it is divisible by 400. Other years divisible by 4 but not by 100 are also leap years.

Example: Year 2000 is a leap year because it is divisible by 400.  Year 2004 is a leap year because it is divisible by 4 but not by 100.

Your program should clearly describe the functionality of each function and should display the instructions on how to run the program.

Your need to create one method “displayMonth” for print each month as required. You can choose return method or not that depend on your design.

Sample Input:

Enter the year for which you wish to generate the calendar: 2004
Enter the day of the week that January first is on: 4

Sample output:

Calendar for year 2004

January
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        31

February
Sun      Mon     Tue      Wed     Thu      Fri        Sat
1          2          3          4          5          6          7
..         ..          ..          ..          ..          ..          ..
..          ..

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace calendar
{
class Program
{
static void Main(string[] args)
{
string[] month = new string[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
int[] days = new int[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int year,dayOfWeek;

Console.Write("Enter the year for which you wish to generate the calendar: ");
year = Convert.ToInt32(Console.ReadLine());

Console.Write("Enter the day of the week that January first is on: ");
dayOfWeek = Convert.ToInt32(Console.ReadLine());

if (isLeapYear(year))
{
days[1] += 1;
}
Console.WriteLine("Calendar for year " + year);
for (int i = 0; i <month.Length; i++)
{
Console.WriteLine("\n\n"+month[i]);
dayOfWeek=printCalender(days[i], dayOfWeek);
}
Console.WriteLine("\n\n");
}
public static int printCalender(int days, int startingDay)
{
int startDay = startingDay;

Console.WriteLine("Sun\tMon\tTue\tWed\tThu\tFri\tSat");
for(int i=0;i<startingDay;i++)
Console.Write("\t");
for (int i = 1; i <= days; i++)
{
if(startDay>6)
{
Console.WriteLine();
startDay=0;
}
Console.Write(i + "\t");
startDay++;
}
  
return startDay;
  
}
public static Boolean isLeapYear(int year)
{
if (year % 4 == 0)
{
if (year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if (year % 400 == 0)
return true;
else
return false;
}
else
return true;
}

return false;
}
}
}

output

another output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Write a C# program that prints a calendar for a given year. Call this program calendar....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C# program that prints a calendar for a given year. Call this program calendar....

    Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs:       1) The year for which you are generating the calendar.       2) The day of the week that January first is on, you will use the following notation to set the day of the week:             0 Sunday                     1 Monday                   2 Tuesday                   3 Wednesday       4 Thursday                 5 Friday                      6 Saturday Your program should...

  • c++ please :) First, ask the user to enter a year (4-digit) and what week day...

    c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....

  • Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day ...

    C++ question Suppose that today is April 1st of the year 2019. By entering your birthday, print what is a day of the week you were born and how many days passed since you were born. Remember that January 1st of the year 2019 is Tuesday See the example below Read 1/1/2019 - Tue 90 Read 4/1/2019 - Mon 0 Read 4/1/2018 - Sun 365 Read 4/1/2017 -> Sat 730 Read 4/1/2016 Fri 1095 Read 4/1/2015-> Wed 1461 Bye... Wikipedia...

  • Work Scheduling: Burger Queen would like to determine the min # of kitchen employees. Each employ...

    Work Scheduling: Burger Queen would like to determine the min # of kitchen employees. Each employee works six days a week and takes the seventh day off. Days Mon Tue Wed Thu Fri Sat Sun Min. # of workers 6 9 How do yu forulaic: ihis problem The objective function? The constraints? Work Scheduling: Burger Queen would like to determine the min # of kitchen employees. Each employee works six days a week and takes the seventh day off. Days...

  • Customer Day Browser Time (min) 12.0 19.5 Pages Viewed Amount Spent (S) Mon Chrome Mon Chrome...

    Customer Day Browser Time (min) 12.0 19.5 Pages Viewed Amount Spent (S) Mon Chrome Mon Chrome Wed Chrome Sun Chrome 54.52 94.90 26.68 44.73 66.27 67.80 36.04 55.96 70.94 68.73 54.04 48.05 64.16 158.51 84.12 59.20 91.62 126.40 Wed Other Tue Firefox Sat Firefox 10.5 Fri Firefox Wed Firefox 12.7 24.7 13.3 Tue Chrome Sat Other Sun Firefox Sun Other Mon Firefox 12 13 24.4 Fri Chrome Thu Chrome Thu Chrome Mon Chrome Fri Other Wed Chrome 18 14.0 15.1...

  • A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes...

    A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year...

  • #1.A For the full HeavenlyChocolates data set, fil in the wing table (to two decimals) ime...

    #1.A For the full HeavenlyChocolates data set, fil in the wing table (to two decimals) ime PagesAmt Spent Mean Standard Deviation Count Confidence Level( 99.0%) #1.B maintain/reject the null hypothesis that the mean value of Time is 12 min. at the .01 level because #1.C maintain/reject the null hypothesis that the mean value of Amt Spent is $70 at the .01 level because #2-A For the full HeavenlyChocolates data set, fill in the correlation table (to two decimals): Time PagesAmt...

  • In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists...

    In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4...

  • please follow format of example output, do in python A year in the modern Gregorian Calendar...

    please follow format of example output, do in python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by...

  • Use Java please Creating a calendar for a given year A shell for this assignment has...

    Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT