edu.kzoo.grid
Class Location

java.lang.Object
  |
  +--edu.kzoo.grid.Location
All Implemented Interfaces:
java.lang.Comparable

public class Location
extends java.lang.Object
implements java.lang.Comparable

AP® Computer Science Marine Biology Simulation:
A Location object represents the row and column of a location in a two-dimensional grid.

The Location class is copyright© 2002 College Entrance Examination Board (www.collegeboard.com).

Version:
1 July 2002
Author:
Alyce Brady, Chris Nevison, APCS Development Committee

Constructor Summary
Location(int row, int col)
          Constructs a Location object.
 
Method Summary
 int col()
          Returns the column coordinate of this location.
 int compareTo(java.lang.Object other)
          Compares this location to other for ordering.
 boolean equals(java.lang.Object other)
          Indicates whether some other Location object is "equal to" this one.
 int hashCode()
          Generates a hash code for this location (will not be tested on the Advanced Placement exam).
 int row()
          Returns the row coordinate of this location.
 java.lang.String toString()
          Represents this location as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Location

public Location(int row,
                int col)
Constructs a Location object.

Parameters:
row - location's row
col - location's column
Method Detail

row

public int row()
Returns the row coordinate of this location.

Returns:
row of this location

col

public int col()
Returns the column coordinate of this location.

Returns:
column of this location

equals

public boolean equals(java.lang.Object other)
Indicates whether some other Location object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
other - the other location to test
Returns:
true if other is at the same row and column as the current location; false otherwise

hashCode

public int hashCode()
Generates a hash code for this location (will not be tested on the Advanced Placement exam).

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code for a Location object

compareTo

public int compareTo(java.lang.Object other)
Compares this location to other for ordering. Returns a negative integer, zero, or a positive integer as this location is less than, equal to, or greater than other. Locations are ordered in row-major order. (Precondition: other is a Location object.)

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
other - the other location to test
Returns:
a negative integer if this location is less than other, zero if the two locations are equal, or a positive integer if this location is greater than other

toString

public java.lang.String toString()
Represents this location as a string.

Overrides:
toString in class java.lang.Object
Returns:
a string indicating the row and column of the location in (row, col) format