Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

namespace Assignment { enum Month { January = 1, February, March, April, May, June, July, August, September, October, November, December } class Calendar { static

namespace Assignment { enum Month { January = 1, February, March, April, May, June, July, August, September, October, November, December }

class Calendar { static void Main(string[] args) { int year; int firstDay;

do { Console.Write("Enter the year for which you wish to generate the calendar: ");

while (!int.TryParse(Console.ReadLine(), out year)) { Console.Write("Invalid input. Please enter a valid year: "); }

Console.Write("Enter the day of the week that January first is on: "); while (!int.TryParse(Console.ReadLine(), out firstDay) || firstDay < 0 || firstDay > 6) { Console.Write("Invalid input. Please enter a valid day of the week: "); }

Console.WriteLine(" "); Console.WriteLine("Calendar for the year " + year);

for (int month = (int)Month.January; month <= (int)Month.December; month++) { Console.WriteLine(); Console.WriteLine(Enum.GetName(typeof(Month), month)); Console.WriteLine("Sun\tMon\tTue\tWed\tThu\tFri\tSat");

int daysInMonth; if (month == 2) { if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) { daysInMonth = 29; } else { daysInMonth = 28; } } else if (month == 4 || month == 6 || month == 9 || month == 11) { daysInMonth = 30; } else { daysInMonth = 31; }

for (int i = 0; i < firstDay; i++) { Console.Write("\t"); }

for (int day = 1; day <= daysInMonth; day++) { Console.Write(day + "\t");

if ((firstDay + day) % 7 == 0) { Console.WriteLine(); } }

firstDay = (firstDay + daysInMonth) % 7; } Console.Write(" Do you want to generate a calendar for another year? (y/n): ");//another year prompt } while (Console.ReadLine().ToLower() == "y"); } } }

How do I rewrite this using Switch Statements?

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 Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions