vendredi 9 novembre 2018

How to utilize a Constructor and methods with an ArrayList?

So this isn't really a specific question, but for this assignment I have I'm given several little members that I need to utilize and I'm pretty confused. What I'm making goes along with a part of a little game my professor made. So my Class name is Bug, and here's what I'm told I need to do:

I need an ArrayList b (that's easy)

I need a Constructor Bug() which initializes 1,2,3 to b. This constructor should also assign a Random object to r.

public int count() should return the current size of b, which I know uses the size method in the Bug object.

public int select() should return one of the moves in c but does not remove the selected move, use the random object to generate a random index into b Bug and return the move at the Index.

public void remove (int m) should remove m from b via remove method in the Bug object.

So here's what I tried right off the bat:

import java.util.ArrayList;
import java.util.Random;

public class Bug {


public static void main(String[] args) { 

ArrayList<Integer> b = new ArrayList<Integer>();
Random r = new Random();
Bug b = new Bug();

}

public int count()
{
return b.size();
}
}

I know this is pretty janky and not right, I'm just having trouble making sense of the directions for this problem, like how to use that Constructor and how to use those methods too. Thanks so much in advance.




Aucun commentaire:

Enregistrer un commentaire