Java基础:根据以下案例编写代码(面向对象)
案例:
声明一个日期类MyDate,包含属性:年、月、日,并在MyDate类中声明几个方法:
1、boolean isLeapYear():判断当前日期的是闰年吗?
2、void set(int y, int m, int d):修改年,月,日为新日期
3、void plus(int y, int m, int d):修改当前日期为加了y年,m月,d天后的日期
效果图:难点在于加上年月日后显示的年月日,需根据每月的天数进位和12个月进位
代码如下:
class IsYear{
public static void main(String[] args){
MyDate my = new MyDate();
my.year = 2019;
my.month = 5;
my.day = 21;
//my.plus(1,1,1);
//my.plus(1,1,20);
//my.plus(1,30,70);
System.out.println(my.year + "年" + my.month + "月" + my.day);
}
}
class MyDate{
int year;
int month;
int day;
boolean isLeapYear(){
if(year%4==0