这可能是明天的考试题目,老师让我们提前准备的
但是传值问题我到现在都没解决,所以很着急
PS:我已经很努力的想过了,也试过很多的方法了的
希望高手有空帮我看看哦
namespace DATE
{
public interface CalendarUnit
{
bool decrement();
}
class Testlt
{
static void Main(string[] args)
{
int a, b, c;
Date date;
Console.WriteLine("请输入你要查询的年!");
a= Convert.ToInt16(Console.ReadLine());
Console.WriteLine("请输入你要查询的月!");
b= Convert.ToInt16(Console.ReadLine());
Console.WriteLine("请输入你要查询的日!");
c = Convert.ToInt16(Console.ReadLine());
date = new Date(a,b,c);
date.printfDate(date.year, date.month, date.day);
date.decrement();
date.printfDate(date.year, date.month, date.day);
}
}
public class Date
{
public Year year = new Year();
public Month month = new Month();
public Day day = new Day();
public Date(int a, int b, int c)
{
if (a < 1 || a > 2006 || b < 1 || b > 12) Console.WriteLine("输入出错!");
if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12)
{
if (c < 1 || c > 31) Console.WriteLine("输入出错!");
}
if (a == 4 || a == 6 || a == 9 || a == 11)
{
if (c < 1 || c > 30) Console.WriteLine("输入出错!");
}
if (year.isleap() == true && b== 2)
{
if (c < 1 || c > 29) Console.WriteLine("输入出错!");
}
if (year.isleap() == false && b == 2)
{
if (c < 1 || c > 28) Console.WriteLine("输入出错!");
}
year .year = a;
month .month = b;
day .day = c;
Console.Read();
}
public bool decrement()
{
day.decrement();
return true;
}
public void printfDate(Year a, Month b, Day c)
{
Console.WriteLine("{0}年{1}月{2}日", a.year , b.month , c.day );
}
}
public class Day :CalendarUnit
{
public int[] sizeIndex ={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Year year2 = new Year();
Month month2 = new Month();
private int day_n;
public int day
{
get
{
return day_n;
}
set
{
day_n = value;
}
}
public bool decrement()
{
if (day == 1)
{
if (month2.num ())
day = 29;
else
day = month2.yyf();
month2.decrement();
return false;
}
else
{
day --;
return true;
}
}
}
public class Month : CalendarUnit
{
Year year1 = new Year();
int month_n;
public int[] sizeIndex ={ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public int month
{
get
{
return month_n;
}
set
{
month_n = value;
}
}
public bool num()
{
if (year1.isleap() && month == 3)
return true;
else
return false;
}
public int yyf()
{
if (month == 1) month = month + 12;
return sizeIndex[month - 1];
}
public bool decrement()
{
if (month == 1)
{
month =12;
year1.decrement();
return false;
}
else
{
month --;
return true;
}
}
}
public class Year : CalendarUnit
{
int year_n;
public int year
{
get
{
return year_n;
}
set
{
year_n = value;
}
}
public bool decrement()
{
year--;
return true;
}
public bool isleap()
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
return true;
else
return false;
}
}
}