/// <summary> /// Function for Calendar /// </summary> public static void CalenderFunction() { try { UtilityFunctions utility = new UtilityFunctions(); Console.WriteLine("Enter month"); int month = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter year"); int date = 1; int year = Convert.ToInt32(Console.ReadLine()); int start = utility.DayOfweek(date, month, year);// Day finding eg. sunday monday string[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; string[] days = { "S", "M", "T", "W", "T", "F", "S" }; Console.WriteLine("Calender " + month + " " + year); Console.WriteLine(months[month - 1] + " " + year); int endDate = utility.EndDate(month, year); for (int i = 0; i < days.Length; i++) { Console.Write(days[i] + " "); } Console.WriteLine(); int j = 1; for (int i = 1; i < endDate + start; i++) { if (i < start) { Console.Write(" "); } else { if (j < 9) { Console.Write(j + " "); } else { Console.Write(j + " "); } j++; } if (i % 7 == 0) { Console.WriteLine(); } } Console.WriteLine(); } catch (Exception e) { Console.WriteLine(e.Message); } }
/// <summary> /// Displays the calender. /// </summary> /// public static void DisplayCalender() { UtilityFunctions utility = new UtilityFunctions(); Queue queue = new Queue(); Console.WriteLine("Enter month"); int month = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter year"); int date = 1; int year = Convert.ToInt32(Console.ReadLine()); string[] months = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; int start = utility.DayOfweek(date, month, year); int endDate = utility.EndDate(month, year); while (start > 1) { queue.Enqueue(" "); start--; } int count = 1; while (count <= endDate) { if (count < 9) { queue.Enqueue(count + " "); } else { queue.Enqueue(count + " "); } count++; } Console.WriteLine(months[month - 1] + " " + year); Console.WriteLine("S |M |T |W |T |F |S"); count = 0; while (!queue.IsEmpty()) { Console.Write(queue.Get()); queue.Dequeue(); count++; if (count % 7 == 0) { Console.WriteLine(); } } Console.WriteLine(); }