method

how would i code a method ( first: void) that if the array is not empty, sets current to the first object.
[113 byte] By [static_firea] at [2007-10-2 20:09:53]
# 1
What? .. this might make sense to you, but seeing as we have no idea of the context your question is posed in, there is no way anyone can answer this.
dwga at 2007-7-13 22:50:25 > top of Java-index,Java Essentials,Java Programming...
# 2

okay this is what i have to do

Code a class named GalacticCommunity. This class has the attributes:

?communityName: String{the name of this Galaxy}

?alienArray: array of AlienCreatures

?lastIndex: int {the index of the last alien in the array}

?current{the index of the alien being viewed}

Code a constructor that accepts an int parameter defining the size of the array.

Code the following methods:

?add(AlienCreature creature): void

?getCurrent(): AlienCreature {returns the AlienCreature at index current}

?first(): void{if the array is not empty, sets current to the first AlienCreature}

static_firea at 2007-7-13 22:50:25 > top of Java-index,Java Essentials,Java Programming...
# 3

this is whatr i have to do

Code a class named GalacticCommunity. This class has the attributes:

?communityName: String{the name of this Galaxy}

?alienArray: array of AlienCreatures

?lastIndex: int {the index of the last alien in the array}

?current{the index of the alien being viewed}

Code a constructor that accepts an int parameter defining the size of the array.

Code the following methods:

?add(AlienCreature creature): void

?getCurrent(): AlienCreature {returns the AlienCreature at index current}

?first(): void{if the array is not empty, sets current to the first AlienCreature}

i dont know how to do the first() method

static_firea at 2007-7-13 22:50:25 > top of Java-index,Java Essentials,Java Programming...
# 4
First define what you mean by "if the array is not empty"? If it has a size > 0? If any elements aren't null? Can there be an element that's null prior to an element that is not null?
kablaira at 2007-7-13 22:50:25 > top of Java-index,Java Essentials,Java Programming...