Modify this activity: static void Main(string[] args) { int current = 1; int ski
ID: 3804746 • Letter: M
Question
Modify this activity:
static void Main(string[] args)
{
int current = 1;
int skip = 0;
int day = 1;
int endDay = 31;
string line = " Sun Mon Tue Wed Thu Fri Sat";
Console.WriteLine(line); //title
line = "";
while (skip < current) //set up the blank part for week 1
{
line += " ";
skip++;
}
while (day <= endDay)
{
while (current < 7 && day <= endDay)
{
line += String.Format("{0,4}", day);
current++;
day++;
}
Console.WriteLine(line);
line = "";
current = 0;
}
And produce an annual monthly calendar from January to December for 2017 using C#. You should modify the program to make it a generalized method for printing monthly calendar. The input could be the weekday of Day 1, the number of days for the month and the return or output could be the next month Day 1's weekday. The initial input could indicate that Jan 1 is a Sunday.
Revised: the first input for the weekday of Day 1(e.g., Day 1 of the month is Sunday or Friday etc.) could be combined with the output for the next month's Day 1's weekday. So, a "ref" reference type of variable could be used.
Sun Mon Tue Wed Thu Fri Sat 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31Explanation / Answer
public static int printMonth(int startDay, int totalDays) {
int current = startDay;
int skip = 0;
int day = 1;
string line = " Sun Mon Tue Wed Thu Fri Sat";
Console.WriteLine(line); //title
line = "";
while (skip < current) //set up the blank part for week 1
{
line += " ";
skip++;
}
while (day <= totalDays)
{
while (current < 7 && day <= totalDays)
{
line += String.Format("{0,4}", day);
current++;
day++;
}
Console.WriteLine(line);
line = "";
current = current%7;
}
return current%7;
}
public static void Main(string[] args)
{
int year = 2017;
string[] months = new string[] {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int[] days = new int[] {31,28,31,30,31,30,31,31,30,31,30,31};
int m = 0;
int currentDay = 0;
while(m < 12) {
Console.WriteLine("+++++++++++++++ " + months[m] + "," + year + " +++++++++++++++++++");
currentDay = printMonth(currentDay, days[m]);
m++;
}
}
Sample Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.