Java program language

For this assignment, you will create several classes:

IMPORTANT NOTE: The following classes are different from the versions of these classes in the first version of this programeven though some share the same name as classes from that version.

Location class, that contains two private instance variables:

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now
  • An int named row
  • An int named column

Add whatever methods you need to this class.

  • Wanderer
  • aCloseSeeker class

Both of these classes should implement an interface called MoverMover should require three public methods:

  • void update();
  • String toString();
  • intgetFoodChainPosition();

Wanderers and CloseSeekers should contain the following private instance variables:

  • intfoodChainPosition
  • MoverController theController

The foodChainPosition of a Wanderer should be set to 1. The foodChainPosition of a CloseSeeker should be set to 2.

  • When asked to update, a Wanderershould try to randomly move one space up, down, left, or right.
  • When asked to update, a CloseSeekershould do the following twice:
    • randomly move one space up, down, left, or right… unless there is a Wanderer in any square it can move to. In that case, it should move onto the
  • Wanderercan never move to the same space as a CloseSeeker.
  • Wanderershould not move if there is a CloseSeeker on its space.
  • CloseSeekershould not move if there is a Wanderer on its space.
  • CloseSeeker can never move to the same space as another CloseSeeker.
  • CloseSeeker can move into the Wanderer‘s space, and should when possible.
  • When toStringis called, Wanderers should return the string: “Wanderer at position (row, column)” and CloseSeekers should return the string “CloseSeeker at position (row, column)”

You will likely find it useful to declare additional methods.

Write another class called MoverController that has the following method:

  • ArrayList<Mover> checkLocation(Location location).

This method should return an ArrayList containing references to all the Movers at that location, if there are Movers at that location. It should return an empty ArrayList if there are no Movers present. When your Movers are asked to update, they should call this method on the controller and use the ArrayList it returns to determine how to move. It may be very useful to call the getFoodChainPosition method on the reference that checkLocation returns.

(why does this return a container? In the middle of a move there might be two Movers on the same space — a Wanderer, and a Seeker which just moved onto that Wanderer. When you check and see if a Wanderer can move, you only want to move if there’s no Seeker present — and if checkLocation simply returned one Mover, it might end up returning the Wanderer that itself called checkLocation.


IMPORTANT:  Here is the control flow for each update:

  1. MoverController calls update on each Moverone by one
  2. update calls checkLocationon MoverController
  3. update uses the results of the checkLocation call or calls to actually select what location to move to, calling getFoodChainPositionon the object returned by checkLocation as necessary.

MoverController should also have one container that contains 25 Movers: 20 Wanderers and 5 CloseSeekers.

In the final version of the program the locations of the Movers should be set randomly. However, for testing it may be useful to explicitly give positions of Wanderers and CloseSeekers, in order to verify that they move properly.

Each turn the MoverController should iterate over the container, sending the update() message to each Mover one by one.  After the MoverController sends an update message to each object, it should use toString() to print information about all objects.

If at the end of the turn a CloseSeeker and a Wanderer occupy the same row and column,  your controller should remove the Wanderer from its container and print the message “Wanderer found at (row, column) on turn [current turn].” When there are no remaining Wanderers in your program should print the message “All Wanderers found in [n] turns” and quit running. There is more than one way for your program to keep track of how many Wanderers are remaining.

Your main function should ask the user to enter a number of turns to run the simulation. If that number of turns passes without all Wanderers being found, print the message “final positions after [n] turns” and then the results of calling toString() on each remaining Mover.

When done, upload all of your classes.


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *