Meaningless Drivel is fun!*
The moose likes Cattle Drive and the fly likes Assignment 3 - hoping for a hint Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Assignment 3 - hoping for a hint" Watch "Assignment 3 - hoping for a hint" New topic
Author

Assignment 3 - hoping for a hint

Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 129
I'm trying to change my code so that I don't have to use the Integer wrapper class.
Here's the error I'm getting:
int cannot be dereferenced
// I've removed the code .. sorry
If this requires doing an explicit cast on the int to an Integer...Please reference a resource that I can lookup that effectively covers this subject. Thanks.

[This message has been edited by Johannes de Jong (edited June 03, 2001).]
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Mike I'm not totally sure I youre code is allowed, so I've removed it.
If you want you can e-mail Marilyn & check if the code was allowed or not.
I do however want to make the following observation. Your line of code does to much its to complicated
I suggest you break it up as follows
  • Assign your input argument to an integer variable
  • then do the mod (%) with that variable to give you your boolean value

  • I would also read up on the equal, I think you should use something else there
    Good luck

    [This message has been edited by Johannes de Jong (edited June 03, 2001).]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
It sounds as though you are trying to use an int as an object. An int is a primitive. An Integer is an object. So is a String. You cannot cast from one to the other in either direction. You must use methods from the wrapper (sounds like Integer in this case) class to convert from object to primitive and back.

The Integer class was not created for calculations. Convert to an int and then calculate.

Also, you use == or equal() for different things. == is for equality of value of primitives and/or testing whether two object references point to the same location in memory.

The equals() method applies whatever test for equality the programmer provides. In java.lang.String, for example, equals() tests whether two String objects have the same content. In java.lang.Object, however, equals() actually is the same as == for objects (described above).

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Mike Cunningham
Ranch Hand

Joined: Nov 14, 2000
Posts: 129
Thanks for the hints.
I'll be more careful in the future about inserting any code into the postings.
I guess I'm still ironing out the fundamentals.
- Mike
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Gee pity I removed the code I cant check now. As far as I remember Mike did not use an object, but if he did I missed the point somewhere.
Pse send Marilyn & me the line of code code if you dont mind Mike. I'd like to clear that up for myself.
Thanks and if I missed the object, thanks for posting the code, I learnt something again
ps this is not an endorsement to post code next time

[This message has been edited by Johannes de Jong (edited June 04, 2001).]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I didn't see the code. I was just trying to cover all the bases.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assignment 3 - hoping for a hint