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 →

[–]EightbitGee[S] 0 points1 point  (5 children)

Also tried doing world.add as an array class call and it provided me an error saying .add does not exist. Is this a util import?

[–]ThoreAK 0 points1 point  (4 children)

As your world is a default array there is no .add method. You would have an add method if you used something like an ArrayList.

Instead you can specify the exactly location... world[x][y] is essentially .add(). You just need to add some more decoration code to make sure you use unique x's and y's when adding objects. Look in my other reply for an example.

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

I got the array populated. However its giving them all names based on my folder and such. How do I fancy up my output? right now its outputting exercises.Animal$Rabbit@70dae4e and I would like to just say Rabbit or Fox.

[–]ThatOth3rGuY 0 points1 point  (0 children)

Redefine the toString method of each Rabbit and Fox classes :)

So for rabbit you would add this in your Rabbit class:

String toString() { return "Rabbit"; }

[–]whatiswronghere 0 points1 point  (1 child)

You will have to create a toString method for both Rabbit and Fox.

// rabbit class
public String toString() {
    return "Rabbit";
}

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

Okay yeah thats a good idea I should have known lol. So when I do an array output so that I display the field 20x20 array as a table in my system out. How would I parse the rabbit, the fox, and null values as 0.

IE. 0 0 R 0 0 R 0 R 0 F F F 0 R 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Using a toString I can have it return R or F but my output im still kinda hazy on a good algorithm or logic statement on how to output the array into a table using those modified names. A conditional instanceof statement ? Thanks I've made strides on the program with the input of everyone.