我正在尝试创建与这些字段对应的属性,但是在不使用 DateTime 类的情况下,我无法制定设置正确日、月和年的逻辑。
因此,用户将一次输入一个数据:按该顺序输入日、月和年。
日期应该在 1 到 30 或 31 或 28 之间 - 基于月份。月份必须介于 1 和 12 之间,年份必须小于或等于 2013
然后我需要制作一个测试用例,它将采用日、月和年的 3 个值并创建一个日期实例。
然后我必须创建一个 Sentinel 控制循环来要求用户输入日、月和年,并使用构造函数创建一个带有用户输入的 Date 实例。如果用户为日、月或年输入 0,则终止程序。
我主要是无法理解逻辑。
public class Date
{
public int Month { get; set; }
public int Day { get; set; }
public int Year { get; set; }
public Date ( int monthValue, int dayValue, int yearValue)
{
Month = monthValue;
Day = dayValue;
Year = yearValue;
}
public int theMonth
{
get {return Month;}
set
{
if (value <= 12) Month = value;
}
}
public int theDay
{
get { return theDay; }
set
{
if (value <= 30) Day = value;
else if (value == 31) Day = value;
else if (value == 28) Day = value;
}
}
public override string ToString()
{
return String.Format( "{0}/{1}/{2}", Month, Day, Year);
}
}