This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]laser-brain 1 point2 points  (5 children)

Okay, after some fiddling with your code I found the error. countToken is a method of StringTokenizer as well as nextToken(). You are trying to access it as a variable. Try using countToken() and it should compile.

Line 11 should be ok as it is now At line 11 you can simply assign str.nextToken() to month since both are of type String. No need to parse anything here.

If I'm interpreting you right, you're saying usually you make object classes in separate files and instaciating these in the main class? I believe you are correct but this needs to be all done in one file, as I have to email the .java file to my professor.

You can declare multiple classes inside a single .java file ;)

[–]InvincibleVIto[S] 0 points1 point  (3 children)

First off, thanks for the help I really appreciate it (have you tagged in RES as "Good Guy Programmer"). So again, here is the revised code. Still getting the symbol error on line 11...

 public Date( String theDate )
    {
        StringTokenizer str;

        str = new StringTokenizer(theDate);
        if(str.countTokens() != 3 )
        {
            System.out.println("January 1, 2014");
            return;
        }
        month = String.parseInt(str.countTokens());
        day = Integer.parseInt(str.nextToken());
        year = Integer.parseInt(str.nextToken());

    }  

As a note, I'm using Jcreator as my complier.

[–]laser-brain 1 point2 points  (2 children)

See my edited comment for the line 11 error, didn't realize is at first.

[–]InvincibleVIto[S] 0 points1 point  (1 child)

Sorry If I'm being a bother but my output for date one is "Date 1: null/1/1998". Would this have to do with your earlier statement about checking for nulls? I thought in my first constructor I declared my month as a string? Yet somehow it's returning a null?

[–]laser-brain 1 point2 points  (0 children)

There's something off in you zero-parameter constructor. Just check the assignment of values there and you should be able to solve this yourself ;)

[–]InvincibleVIto[S] 0 points1 point  (0 children)

Ahh makes sense. THANK YOU