using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
namespace FixTest
{
class Program
{
static void Main(string[] args)
{
int remainTime = 0;
int[] time = InputTimeOfTermStart();
int[,,] table = RandomMakeAClassTable();
DateTime currentTimeNow = new DateTime();
currentTimeNow = DateTime.Now;
for (;;)
{
int[] currentTime = GetCurrentTime(currentTimeNow);
int currentWeek = CalculateCurrentWeek(time, currentTime);
ShowWeekTableHead(currentWeek);
ShowWeedTableBody(table, currentWeek);
int controlItem = InputControlItem();
switch (controlItem)
{
case 1:
{
Console.Clear();
int number = InputANumberAsSelectWeek();
ShowWeekTableHead(currentWeek);
ShowWeedTableBody(table, number);
}
break;
case 2:
{
Console.Clear();
remainTime = CalculateRemainTimeToNextClass(currentTime, table, time);
ShowRemainTimeToNextClass(remainTime);
}
break;
case 3:
{
Console.Clear();
int interval = GetATimeInterval(currentTime);
remainTime = CalculateRemainTimeToNextClass(currentTime, table, time);
GoToClubIsOrNot(interval, remainTime);
}
break;
case 4:
{
Console.Clear();
DateTime now = SetCurrentTime();
currentTimeNow = now;
GetCurrentTime(currentTimeNow);
}
break;
case 5:
{
Environment.Exit(0);
}
break;
}
}
}
static int[] InputTimeOfTermStart()
{
{
MyLabel:
Console.WriteLine("Enter a time as the first day of new semester : as 1800,1,1");
string time = Console.ReadLine();
string[] sArray2 = Regex.Split(time, ",");
int[] timeArray = new int[3];
try
{
timeArray[0] = Convert.ToInt32(sArray2[0]);
timeArray[1] = Convert.ToInt32(sArray2[1]);
timeArray[2] = Convert.ToInt32(sArray2[2]);
}
catch (FormatException)
{
Console.WriteLine("You are exist input error! ");
goto MyLabel;
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("You are exist input error! ");
goto MyLabel;
}
return timeArray;
}
}
static int[,,] RandomMakeAClassTable()
{
int[,,] table = new int[21, 5, 8];
Random random = new Random();
for (int i = 0; i < table.GetLongLength(0); i++)
{
for (int j = 0; j < table.GetLongLength(1); j++)
{
for (int k = 0; k < table.GetLongLength(2); k++)
{
if (k == 0)
{
table[i, j, k] = j + 1;
}
else
{
int temple = random.Next(200, 215);
if (temple % 5 == 0)
table[i, j, k] = 0;
else
table[i, j, k] = temple;
}
}
}
}
return table;
}
static int[] GetCurrentTime(DateTime currentTime)
{
int[] currentTimeArray = new int[6];
currentTimeArray[0] = currentTime.Year;
currentTimeArray[1] = currentTime.Month;
currentTimeArray[2] = currentTime.Day;
currentTimeArray[3] = currentTime.Hour;
currentTimeArray[4] = currentTime.Minute;
currentTimeArray[5] = (int)currentTime.DayOfWeek;
return currentTimeArray;
}
static int CalculateCurrentWeek(int[] time, int[] currentTime)
{
int cyear = 0, cmonth = 0, cday = 0;
cyear = currentTime[0];
cmonth = currentTime[1];
cday = currentTime[2];
int year = 0, month = 0, day = 0;
year = time[0];
month = time[1];
day = time[2];
int days = 0;
for (int i = month; i < cmonth; i++)
{
if (((cyear % 4 == 0) && (cyear % 100 != 0)) || (cyear % 400 == 0))
{
if (i == 1 || i == 3 || i == 5
|| i == 7 || i == 8 || i == 10 || i == 12)
{
days += 31;
}
else if (i == 2)
{
days += 29;
}
else
{
days += 30;
}
}
else
{
if (i == 1 || i == 3 || i == 5
|| i == 7 || i == 8 || i == 10 || i == 12)
{
days += 31;
}
else if (i == 2)
{
days += 28;
}
else
{
days += 30;
}
}
}
days += cday - day;
int currentWeek = 0;
currentWeek = days / 7 + 1;
return currentWeek;
}
static void ShowWeekTableHead(int currentWeek)
{
Console.WriteLine("Current Week Is (" + currentWeek + " / 21 )");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\t\tSun\t\t Mon\t\t Thu\t\t Wed\t\t thu\t\t Fri\t\t Sat");
}
static void ShowWeedTableBody(int[,,] table, int week)
{
int i = week - 1;
for (int j = 0; j < table.GetLongLength(1); j++)
{
for (int k = 0; k < table.GetLongLength(2); k++)
{
Console.BackgroundColor = ConsoleColor.Green;
Console.ForegroundColor = ConsoleColor.Black;
int temple = table[i, j, k];
if (k == 0)
{
switch (table[i, j, k])
{
case 1:
Console.Write("8:00 ~ 9:30\t");
break;
case 2:
Console.Write("10:00 ~ 11:30\t");
break;
case 3:
Console.Write("14:00 ~ 15:30\t");
break;
case 4:
Console.Write("16:00 ~ 17:30\t");
break;
case 5:
Console.Write("18:30 ~ 20:00\t");
break;
}
}
else
{
if (temple % 5 == 0)
Console.Write("--------\t");
else
Console.Write("class{0}\t", temple);
}
}
Console.WriteLine("\n");
}
Console.WriteLine();
Console.WriteLine();
}
static int InputControlItem()
{
Console.WriteLine
("1. 查看课程表。\n2. 距离下一堂课开始还有多久!"
+ "\n3. 判断当前时间是否适合去俱乐部\n4. 修改当前日期!\n5. 退出!");
Console.WriteLine("please enter you selected item from 1 to 5!");
string item = Console.ReadLine();
Console.Clear();
int intItem = 0;
try
{
intItem = Convert.ToInt32(item);
if (intItem <= 5 && intItem >= 1)
return intItem;
else
{
Console.WriteLine("You must enter a number from 1 to 5 !");
return 0;
}
}
catch
{
Console.WriteLine("You must enter a number!");
return 0;
}
}
static int InputANumberAsSelectWeek()
{
Lable:
Console.WriteLine("please selete the week from 1 to 21!");
string week = Console.ReadLine();
int intWeek = 0;
try
{
intWeek = Convert.ToInt32(week);
Console.WriteLine("This is " + intWeek + "th week");
}
catch
{
Console.WriteLine("You write error!");
goto Lable;
}
return intWeek;
}
static int CalculateRemainTimeToNextClass(int[] currentTime, int[,,] table, int[] time)
{
int interval = GetATimeInterval(currentTime);
int deffer = 0;
int dayOfWeek = currentTime[5];
int hour = currentTime[3];
int minute = currentTime[4];
int currentWeek = CalculateCurrentWeek(time, currentTime);
switch (interval)
{
case 1:
{
deffer = (9 - hour) * 60 + 30 - minute;
if(table[currentWeek,1,dayOfWeek] == 0)
{
deffer += 120;
}
}
break;
case 2:
{
deffer = (9 - hour) * 60 + 30 - minute;
if (table[currentWeek, 1, dayOfWeek] == 0)
{
deffer += 120;
}
}
break;
case 3:
{
deffer = (11 - hour) * 60 + 30 - minute;
if (table[currentWeek, 2, dayOfWeek] == 0)
{
deffer += 120;
}
}
break;
case 4:
{
deffer = (14 - hour) * 60 - minute;
if (table[currentWeek, 2, dayOfWeek] == 0)
{
deffer += 120;
}
}
break;
case 5:
{
deffer = (15 - hour) * 60 + 30 - minute;
if (table[currentWeek, 3, dayOfWeek] == 0)
{
deffer += 180;
}
}
break;
case 6:
{
deffer = (16 - hour) * 60 - minute;
if (table[currentWeek, 3, dayOfWeek] == 0)
{
deffer += 120;
}
}
break;
case 7:
{
deffer = (17 - hour) * 60 - minute;
if (table[currentWeek, 4, dayOfWeek] == 0)
{
deffer += 540;
}
}
break;
case 8:
{
deffer = (19 - hour) * 60 + 30 - minute;
if (table[currentWeek, 4, dayOfWeek] == 0)
{
deffer += 540;
}
}
break;
case 9:
{
deffer = (24 - hour + 8) * 60 - minute;
if (table[currentWeek, 1, dayOfWeek + 1] == 0)
{
deffer += 660;
}
}
break;
case 10:
{
if (currentTime[3] < 24)
{
deffer = (24 - hour + 8) * 60 - minute;
if (table[currentWeek, 1, dayOfWeek + 1] == 0)
{
deffer += 600;
}
}
else
{
deffer = (8 - hour) * 60 - minute;
if (table[currentWeek, 1, dayOfWeek + 1] == 0)
{
deffer += 120;
}
}
}
break;
}
return deffer;
}
static void ShowRemainTimeToNextClass(int remainTime)
{
int hours = remainTime / 60;
int minutes = remainTime % 60;
Console.WriteLine("The time to next reamin " + hours + " hours and " + minutes + " minures");
}
static int GetATimeInterval(int[] time)
{
int hour = time[3];
int minute = time[4];
if ((hour >= 8 && hour == 9) || (hour == 9 && minute <= 30))
{
return 1;
}
else if (hour == 9 && minute > 30)
{
return 2;
}
else if (hour == 10 || (hour == 11 && minute <= 30))
{
return 3;
}
else if ((hour == 11 && minute > 30) || hour == 12 || hour == 13)
{
return 4;
}
else if (hour == 14 || (hour == 15 && hour <= 30))
{
return 5;
}
else if (hour == 15 && minute > 30)
{
return 6;
}
else if (hour == 16 || (hour == 17 && minute <= 30))
{
return 7;
}
else if (hour == 17 && minute > 30)
{
return 8;
}
else if (hour == 19 || hour == 20)
{
return 9;
}
else
{
return 10;
}
}
static DateTime SetCurrentTime()
{
Label:
Console.WriteLine("Enter a time as Currentime like as 1800,1,1,0,0");
string time = Console.ReadLine();
string[] sArray = Regex.Split(time, ",");
DateTime currentTime = new DateTime();
currentTime = DateTime.Now;
DateTime nowTime = new DateTime();
nowTime = DateTime.Now;
try
{
int year = Convert.ToInt32(sArray[0]);
int month = Convert.ToInt32(sArray[1]);
int day = Convert.ToInt32(sArray[2]);
int hour = Convert.ToInt32(sArray[3]);
int minute = Convert.ToInt32(sArray[4]);
currentTime = currentTime.AddYears(year - nowTime.Year );
currentTime = currentTime.AddMonths(month - nowTime.Month);
currentTime = currentTime.AddDays(day - nowTime.Day);
currentTime = currentTime.AddHours(hour - nowTime.Hour);
currentTime = currentTime.AddMinutes(minute - nowTime.Minute);
}
catch (FormatException)
{
Console.WriteLine("You exist input error! ");
goto Label;
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("You exist input error! ");
goto Label;
}
return currentTime;
}
static void GoToClubIsOrNot(int interval, int remainTime)
{
switch (interval)
{
case 1:
{
Console.WriteLine("You are in the class, not go to club !");
}
break;
case 2:
{
if (remainTime > 90)
Console.WriteLine("You can go to club ! ");
else
Console.WriteLine("The time is too short , you should not go to club");
}
break;
case 3:
{
Console.WriteLine("You are in the class, not go to club");
}
break;
case 4:
{
Console.WriteLine("The time you should rest !");
}
break;
case 5:
{
Console.WriteLine("You are in the class, not go to club");
}
break;
case 6:
{
if (remainTime > 90)
Console.WriteLine("You can go to club ! ");
else
Console.WriteLine("The time is too short , you should not go to club");
}
break;
case 7:
{
Console.WriteLine("You are in the class, not go to club");
}
break;
case 8:
{
if (remainTime > 90)
Console.WriteLine("You can go to club ! ");
else
Console.WriteLine("The time is too short , you should not go to club");
}
break;
case 9:
{
Console.WriteLine("You are in the class, not go to club");
}
break;
case 10:
{
Console.WriteLine("The time you should rest !");
}
break;
}
}
}
}
说实话,我没搞得你想问什么, 叫我们测你的代码,然后发现问题,最后帮你修复?
你可以自己多run run,然后把问题抛出来!
别像现在这样。
就是第一个功能查询课表的功能 不能实现 总是在一张课表里 调试了半天也没搞懂怎么回事!
谢谢了哈!
请问楼主这是要闹哪般,你说有问题就把问题贴出来,不要把代码全部贴出来。你这是想让我们自己找你的问题吗?不谦虚!!!!
就是第一个功能查询课表的功能 不能实现 总是在一张课表里 调试了半天也没搞懂怎么回事!
谢谢了哈!
建议好好看看“提问的艺术”,相信对你会有帮助
ok