...
[rmh3093.git] / project1 / Location.java
blob84faaf92b6b8e063c4eb4c44ac060260a869f303
1 /*
2 * Location.java
4 * Version:
5 * $Id: Location.java,v 1.2 2008/04/11 17:53:12 rmh3093 Exp rmh3093 $
7 * Revisions:
8 * $Log: Location.java,v $
9 * Revision 1.2 2008/04/11 17:53:12 rmh3093
10 * finding words works
12 * Revision 1.1 2008/03/31 03:58:55 rmh3093
13 * Initial revision
17 /**
18 * This class represents the location of a word in a word search puzzle. The
19 * location of a word is given as the coordinates of the first and last
20 * characters in the word. A coordinate consists of the row and column in the
21 * puzzle grid. Rows and columns are numbered from 0 to R-1 and C-1 respectively
22 * (where R and C are the number of rows and columns in the puzzle grid.
24 * @author rmh3093
26 public class Location {
28 int sRow; //the row of the first character
29 int sCol; //the column of the first character
30 int eRow; //the row of the last character
31 int eCol; //the column of the last character
33 /**
34 * Create a location of [(0,0) (0,0)]
36 public Location() {
37 sRow = sCol = eRow = eCol = 0;
40 /**
41 * Create a location of [(sRow,sCol) (eRow,eCol)]
43 * @param sRow the row of the first character
44 * @param sCol the column of the first character
45 * @param eRow the row of the last character
46 * @param eCol the column of the last character
48 public Location(int sRow, int sCol, int eRow, int eCol) {
49 this.sRow = sRow;
50 this.sCol = sCol;
51 this.eRow = eRow;
52 this.eCol = eCol;
55 /**
56 * Return the row number in the puzzle that contains the first letter in
57 * the word.
59 * @return
61 public int getStartRow() {
62 return sRow;
65 /**
66 * Set the row number in the puzzle that contains the first letter in the
67 * word.
69 * @param sRow row containing the first letter of the word
71 public void setStartRow(int sRow) {
72 this.sRow = sRow;
75 /**
76 * Return the column number in the puzzle that contains the first letter in
77 * the word.
79 * @return
81 public int getStartCol() {
82 return sCol;
85 /**
86 * Set the column number in the puzzle that contains the first letter in the word.
88 * @param sCol column containing the first letter of the word
90 public void setStartCol(int sCol) {
91 this.sCol = sCol;
94 /**
95 * Return the row number in the puzzle that contains the last letter in the
96 * word.
98 * @return
100 public int getEndRow() {
101 return eRow;
105 * Set the row number in the puzzle that contains the last letter in the
106 * word.
108 * @param eRow row containing the last letter of the word
110 public void setEndRow(int eRow) {
111 this.eRow = eRow;
115 * Return the column number in the puzzle that contains the last letter in
116 * the word.
118 * @return
120 public int getEndCol() {
121 return eCol;
125 * Set the column number in the puzzle that contains the last letter in the
126 * word.
128 * @param eCol column containing the last letter of the word
130 public void setEndCol(int eCol) {
131 this.eCol = eCol;
135 * Convert this Location to a string. The string must adhere to the
136 * following format: [(startRow,startCol) (endRow,endCol)]
138 public String toString() {
139 return "[(" + sRow + "," + sCol + ") (" + eRow + "," + eCol + ")]";
143 * Compare this Location to the Location given as an argument. The result is
144 * true if and only if the argument is not null and it represents the same
145 * location as this object. Two locations are the same if their startRow,
146 * startCol, endRow, and endCol are the same.
148 * @param other
149 * @return
151 public boolean equals(Location other) {
152 boolean ret = false;
153 if (other != null) {
154 if (this.eCol == other.getEndCol()) {
155 if (this.eRow == other.getEndRow()) {
156 if (this.sCol == other.getStartCol()) {
157 if (this.sRow == other.getStartRow()) {
158 ret = true;
164 return ret;