Two Laptop Bag*
The moose likes Beginning Java and the fly likes boolean array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean array" Watch "boolean array" New topic
Author

boolean array

DANIEL GRESHAM
Greenhorn

Joined: Feb 09, 2005
Posts: 21
is there any way to place a charecter on a (primative data type)2d boolean array denoting a position that is not a boolean assigned value? ie if my case returns thaat im moving north, and I want place a "^" in my current index floor[_current_row][_current_col]. any help would be much appreciated
thank you in advance
Danny
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

If the array is defined to hold boolean values, then it can only hold boolean values.

If you want these array elements to store information beyond "true" or "false," then you might reconsider the array type.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Can you describe what you're trying to accomplish instead of starting with the how? I'm guessing you're making a maze where the floor matrix (two dimensional array) value at each position is true to represent a wall and false to represent open space. If that's correct, why do you want to store a '^' there? What does that represent?

If you can explain that part, we can suggest other ways to go about it. As Marc said, booleans hold either true or false -- that's it. You could switch to a numeric type like byte/short/int and define appropriate constants.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Actually, I was wondering whether Java's new enum feature might be helpful here.
DANIEL GRESHAM
Greenhorn

Joined: Feb 09, 2005
Posts: 21
my boolean array is an imaginary floor that a rat can traverse, the rat can move in 8 directions, north, north east, yada yada yada. The rat has a pen attached to its tail, when the pen is up it moves and I currently have the code
System.out.println("My current position is row," + (_current_row + 1) + " column," + (_current_col + 1) + " and I am facing (//whatever direction respectively//)");
I would like to replace this with a directional arrow of some kind. Ok forgive my ignorace on this issue, but I've heard of something called "overloading?" does this apply? Sorry, Im only on the array chapter in my book, so I have no idea what this really is or hwat it does.
DANIEL GRESHAM
Greenhorn

Joined: Feb 09, 2005
Posts: 21
By the way thanx for the help thus far
-Danny-
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
From your descriptino I gather that on top of the floor array you also track the current row, column, and facing direction of the rat and whether the pen is up or down. These should be stored separate from the floor array in my opinion.

A Rat class could track the first three and a Pen class the pen's state. Do you need to record everywhere the rat went? Is that what the floor array tracks? You need to specify all the things your program needs to "know" (keep track of) at all times and model them somehow.

Can you correct what I have above?

Finally, you also mention you want to replace a line saying "I'm at x, y, facing z" with a "directional arrow". Is that all that you want to display? You've got decent choices for the four cardinal directions -- < > v ^ -- but I'm not sure what you'll do about the diagonal ones.

Marc, I usually don't advise the JDK 1.5 features simply because many people cannot use it yet or will get used to it starting out and then start a job where they can't use it. Have you found this to be changing? My projects have just started using JDK 1.4.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by David Harkness:
...I usually don't advise the JDK 1.5 features simply because many people cannot use it yet or will get used to it starting out and then start a job where they can't use it...

You're absolutely right! I think we just moved to Java 1.4 at work (although I'm technically a Lotus Notes Developer -- not a Java Programmer). I mentioned the enum feature only because I'm curious whether this would actually be an appropriate use of it. I've only read about it, and am still unclear on the benefits.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you settle on how to draw your direction, you can definitely make an array of graphics or ascii graphics and pick the right one out. So with the numbers representing directions as David showed above:

System.out.print("I'm facing " + displayDirection[ direction ] );

Ascii graphics may be a bit tough to do on a single line. The strings "east" , "west", "northeast" or whatever would be dead easy, tho.

String[] displayDirection = new String[] { "east", "west" ... }


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: boolean array
 
Similar Threads
2d Boolean Array
maze solve
Connection Array into an adjacency Matrix
OutOfBounds Exception: 0
hashmap vs searching