# Location Worksheet (DOC) by keralaguest

VIEWS: 55 PAGES: 1

• pg 1
```									Name                                                                                             Period
AP Computer Science A

Location Worksheet

Write Java statements for each of the following. Use the API for the Direction and the Location classes.

1.      Create an Actor reference named dir1. Instantiate the object using the no-arg Actor constructor.
2.      Create an Actor reference named dir2. Instantiate the object, then set the direction using modifier
method with an int.
3.      Create an Actor reference named dir3. Instantiate the object, then set the direction using modifier
method with a negative int.
4.      Create an Actor reference named dir4. Instantiate the object, then set the direction using modifier
method with Location.SOUTH.
5.      Create a Actor reference named dir5. Let dir5 have a random direction (use Math.random() ).
6.      Let dir1 face its reverse direction.
7.      Let dir2 face dir3's reverse direction.
8.      Let dir3 face the direction 90 degrees to its left.
9.      Let dir4 face the direction 180 degrees to its right.
10.     Let dir5 face the direction 90 degrees to dir1's right.
11.     Output the dir1's number of degrees.
12.     Change dir1's direction to a random direction if dir1 face the same direction as dir2, otherwise
change dir2's direction to a random direction.
13.     Output dir1 and dir5.

Location class
14.   Create a Location reference named loc1. Instantiate the object with a row number of 2 and a
column number of 4.
15.   Create a Location reference named loc2. Instantiate the object with a row number of 6 and a
column number of 3.
16.   Create a Location reference named loc3. Instantiate the object with a row number of 2 and a
column number of 3.
17.   Output the row numbers for each of the Location references.
18.   Output loc1 if it is greater than loc2, otherwise output loc2.
19.   Check to see if loc2 and loc3 are equal. Output an appropriate statement if there are equal or if they
are not equal.
20.   Output loc1, loc2, and loc3.
21.   Complete the following method for some class to create and return a random location.

private static Random rg = RandNumGenerator.getInstance();

// returns a Location with a row value in the range [0,numRows-1] and
// column value in the range [0,numCols – 1]
public Location randomLocation(int numRows, int numCols)
{

}

AP Computer Science                         Location Worksheets                                           6/15/11

```
To top