Java,要求具体过程(用构造方法)

img

MyDate:


public class MyDate {
    private int year;
    private int month;
    private int day;
    
    public MyDate(int y,int m,int d){
        year = y;
        month = m;
        day = d;
    }
    public void showDate(){
        System.out.println(year+"-"+month+"-"+day);
    }
    public boolean isBi(){
        if(year%4==0 && year%100!=0 || year%400==0)
            return true;
        else
            return false;
    }
    public int getYear() {
        return year;
    }
    public void setYear(int year) {
        this.year = year;
    }
    public int getMonth() {
        return month;
    }
    public void setMonth(int month) {
        this.month = month;
    }
    public int getDay() {
        return day;
    }
    public void setDay(int day) {
        this.day = day;
    }

}

Test:

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        MyDate dt = new MyDate(2021,11,20);
        dt.showDate();
        if(dt.isBi())
            System.out.println(dt.getYear()+"是闰年");
        else
            System.out.println(dt.getYear()+"不是闰年");
    }

}