Wyo Java Ch7Proj1

Implement the default constructor and the move method in the Fish class provided in the Handout folder. The move method must allow a Fish object variable named nemo to move through an unbounded ocean. The ocean is represented as a grid where each location is an (x, y) ordered pair. During each move, nemo can go in any horizontal or vertical direction except for backwards. He cannot move diagonally. For example, if nemo is currently in location (0, 0) and his myDirection property is 1 (meaning North) then this his new location will be (0, -1). That is, his myX property will be 0 and his myY property will be -1. We are using the graphics coordinate system that we used in Visual Basic where the y-axis is "reversed". After this move, he is allowed to turn in any direction, except for backwards, or continue in the same direction with equal probability. If his original myDirection property value is 1, then his new myDirection property value may be 1, 2, or 4 at the end of the move method. His myDirection cannot be 3 since that would indicate a 180 degree turn in the backwards direction. Use the static Random object provided in the Fish class to generate pseudorandom values to determine which direction nemo will go with equal probability on each move.

Also, complete the Ch7Proj1 client program where nemo must initially be positioned at the location (0, 0). Then, use a loop to allow nemo to move 20 times. Each move will be one position in the ocean. After each move, take advantage of the provided toString method to display nemo's id, location, and direction on a separate line. Display your name and the project name on the first line of output.

Here is a sample output.

Your program must follow the class Coding Standards. Save all of the files associated with this assignment to a folder named Ch7Proj1 in the appropriate network folder.

Preconditions:

    • None

You must hand in the following on separate pages stapled in this specified order:

    1. The source code for the Ch7Proj1 class.
    2. The Fish class.
    3. The printscreen of your console window output. Be sure to print black text on white background.