Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java: Date Checking

Name: Anonymous 2011-04-08 0:01

Why does this not work; why do I suck at programming;


public static boolean validDate(int m, int d, int y){
        if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12){
            if (d < 1 || d > 31)
                return false;
            return true;
        }else if (m == 4 || m == 6 || m == 9 || m == 11){
            if (d < 1 || d > 30)
                return false;
            return true;
        }else if (m == 2){
            if ( d < 1 || d > 29)
                return false;
            if (d == 29 && leapYear(y))
                return false;
            return true;
        }
        return false;
    }


it doesn't even work for absurdly wrong dates like 1234/1234/1234

Name: Anonymous 2011-04-08 0:01

this is leapYear()

private static boolean leapYear(int y){
           if ( y % 4 != 0 )
               return false;
           if ( y % 100 != 0 )
               return true;
           if ( y % 400 != 0 )
               return false;
           return false;
    }

Name: Anonymous 2011-04-08 0:07

What doesn't work?

Name: Anonymous 2011-04-08 0:09

>>3

public Date(int m, int d, int y){
        day = d;
        month = m;
        year = y;
        if (!validDate(m,d,y))
            throw new IllegalArgumentException("Invalid Date");
    }


this exception is NEVER thrown

Name: Nambla_dot_org_rules_you 2011-04-08 0:18

Holy crappy Java code.

Name: Anonymous 2011-04-08 0:21

>>5

You're just going to town trolling tonight, aren't you.
Regardless of your retardness, I'm not very proud of this program at all.

Name: Anonymous 2011-04-08 0:28

Christ, just run it through a debugger

Name: nambla_dot_org_rules you 2011-04-08 0:31

Okay, listen you fat autistic jew. I don't code on the level of "total retard aka SICP monkey". With that, here is how a real programmer would write the leapYear method..

private static boolean leapYear(int year) {
  return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}

Now maybe both you and the OP should do something that requires a little less mental power. Like rattling about Jewish Zionism.

Name: Anonymous 2011-04-08 0:42

>>1
It's supposed to work, at least for "absurdly wrong dates like 1234/1234/1234". Other than that, insert print statements to see what's going on. Good luck, ``faggot''.

Name: Anonymous 2011-04-08 0:49

>>4
NO EXCEPTIONS

Name: Anonymous 2011-04-08 2:37

>>1

mailto:noko

Back to the imageboards, please

Name: Anonymous 2011-04-08 2:40

>>11
fock uff end dia, plaese

Name: VIPPER 2011-04-08 2:41

JDate Checking

Name: Anonymous 2011-04-08 4:21

>>12
Back to school, please

Name: Anonymous 2011-04-08 7:46

1234/1234/1234 is ENTERPRISE DATE it cannot be INVALID

Name: Anonymous 2011-04-08 10:05

On first glance, you mena
if (d == 29 && leapYear(y)) return true;

Name: nambla_dot_org_still_rules_you 2011-04-08 11:04

But it will still bork because the OP didn't bother to google the definition of a leap year.

Name: Anonymous 2011-04-08 16:18

lern2debug

Name: Anonymous 2011-04-08 19:17

>>14
fuck off and die you cock sucking faggot i fucking hate you

Name: Anonymous 2011-04-08 19:29

>>19
Perhaps you are mad because you should you should go back to school you fucking``faggot''

Name: Anonymous 2011-04-08 19:40

>>20
fuck off and die you fucking faggot

Name: Anonymous 2011-04-08 19:55

>>21
fuck off and die you fucking faggot

>>19
fuck off and die you cock sucking faggot i fucking hate you

Name: Anonymous 2011-04-08 20:38

>>22
fuck you faggot

Name: Anonymous 2011-04-09 3:56

Constructive discussion is constructive, please, carry on /prog/ and never change also, ANUS

Name: Anonymous 2011-04-09 4:59

>>24
X y is x.
Back to the imageboards, ``please''.

Name: Anonymous 2011-04-09 5:48

>>25
fuck you faggot

Name: Anonymous 2011-04-09 6:39

>>26
Why do you want to fuck ``faggots" so much?

Back to the bathhouse, please.

Name: RedCream 2011-04-09 6:57

>>27
You first.

Name: VIPPER 2011-04-09 15:51

JEWS

Name: VIPPER 2011-04-09 15:53

JEWS

Name: VIPPER 2011-04-09 15:55

JEWS

Name: VIPPER 2011-04-09 15:57

JEWS

Name: VIPPER 2011-04-09 15:59

JEWS

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List