package com.sf.day07;

import com.sun.org.apache.bcel.internal.generic.NEW;

import java.time.Year;
import java.util.Date;
import java.util.Scanner;

public class MyDate {
    private Integer year;
    private Integer month;
    private Integer day;

    public MyDate() {
    }

    public MyDate(Integer year, Integer month, Integer day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public Integer getDay() {
        return day;
    }

    public void setDay(Integer day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }

    //判断是否为闰年
    public boolean isLeapYear(Integer year){
        if(year % 4 == 0 && year % 400 !=0 || year % 100 ==0){
            return true;
        }
        return false;
    }

    /**
     * 修改年月日

     */
    public void set(){
        System.out.println("请输入新日期 --年：");
        Scanner scanner = new Scanner(System.in);
        this.year = scanner.nextInt();
        System.out.println("请输入新日期 --月：");
        this.month = scanner.nextInt();
        System.out.println("请输入新日期 --日：");
        this.day = scanner.nextInt();
    }

    /**
     * 加日期
     */
    public static MyDate puls(MyDate myDate){
        Scanner scanner = new Scanner(System.in);
        Integer year1 = myDate.getYear();
        Integer month1 = myDate.getMonth();
        Integer day1 = myDate.getDay();

        System.out.println("年");
        int year2 = scanner.nextInt();
        System.out.println("月");
        int month2 = scanner.nextInt();
        System.out.println("日");
        int day2 = scanner.nextInt();

        Integer newYear = year1+year2;

        Integer newMonth = month1+month2;

       Integer newDay = day1+day2;

       if(newDay > 30){
           newMonth = newMonth+1;
           newDay-=30;
           if(newMonth>12){
              newYear = newYear + 1;
              newMonth  -= 12;
           }
       }

        MyDate myDate1 = new MyDate();
        myDate1.setYear(newYear);
        myDate1.setMonth(newMonth);
        myDate1.setDay(newDay);
        return myDate1;
    }

    public static void main(String[] args) {
        MyDate myDate = new MyDate();
        myDate.set();
        System.out.println(myDate);  //2022   12  01
        MyDate date = puls(myDate);
        System.out.println(date);
    }
}
