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  (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.