mercredi 3 octobre 2018

I'm very beginner at Java and

im a beginner at java and am trying to make a code where it just shows birth of the object thought would be simple but got stuck here

    public int day(int x) {
    if (month == Feb) {
        if(year%4 == LeapYear) {
            day = (x>29 || x<=0 ? 0 : x);
        } else {
            day = (x>28 || x<=0 ? 0 : x);
        }
    }
    else if(month==4 || month==6 || month==9 || month==11) {
        day = (x>30 || x<=0 ? 0 : x);
    }
    else {
        day = (x>31 || x<=0 ? 0 : x);
    };
    return day;
}
public int month(int x) {
    month = (x>12 || x<=0 ? 0 : x);
    return month;
}
public int year(int x) {
    year = (x>2010 || x<=1940 ? 0 : x);
    return year;
}

so the problem that happens is that it allows 29 on non-leap years even though i said dont i tried to do it this way too but it brings up cannot turn from int to boolean

if (month == Feb && year%4 == LeapYear) {
    day = (x>29 || x<=0 ? 0 : x);
} 
else if (month == Feb && year%4 \= LeapYear) {
    day = (x>28 || x<=0 ? 0 : x);
}

idk how to fix it should i use (.equals)? if so how do i use .equals in this situation?

Aucun commentaire:

Enregistrer un commentaire