Write a new public method in your Beach class called addTurtle(). This method should pick a random x/y location (e.g., using Random.generator()) on the beach and add a single Turtle there.
public class Main { public static void main(String[] args) throws IOException { //BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
Beach beach = new Beach();
beach.addTurte();
} }
class Turtle { private int mX; private int mY; public Turtle(int x, int y) { mX = x; mY = y; }
public int x() { return mX; } public int y() { return mY; } }
class Beach { private Vector<Turtle> mVectorTurtle;
public Beach() { mVectorTurtle = new Vector<Turtle>(); } public void addTurte() { Random rand = new Random(); Turtle turtle = new Turtle(rand.nextInt(), rand.nextInt()); mVectorTurtle.add(turtle); } }
Comments
Leave a comment