// // Coordinate.java // import java.lang.String; import java.util.Vector; import java.util.Enumeration; public class Coordinate { // OVERVIEW: A Coordinate is a mutable datatype that represents a point in 2D cartesian space. // A typical coordinate is . /*@spec_public@*/ private int x; /*@spec_public@*/ private int y; Coordinate(int p_x, int p_y) // EFFECTS: Constructs a new Coordinate (p_x, p_y). { x = p_x; y = p_y; } Coordinate(/*@non_null@*/ Coordinate c) { x = c.getX(); y = c.getY(); } public int getX() //@ensures \result == x; { return x; } public int getY() //@ensures \result == y; { return y; } public void setX(int p_x) //@ensures this.x == p_x; { x = p_x; } public void setY(int p_y) //@ensures this.y == p_y; { y = p_y; } public String toString() { return "(" + x + ", " + y + ")"; } public boolean equals(Object c) { if (c == null || !(c instanceof Coordinate)) { return false; } else { Coordinate b = (Coordinate) c; return (x == b.getX() && y == b.getY()); } } //@requires coords.elementType == \type(Coordinate) //@requires coords.containsNull == false //@requires coords != null static public String outputCoordinates(Vector coords) { StringBuffer res = new StringBuffer(coords.size() * 8); Enumeration e = coords.elements(); while (e.hasMoreElements()) { Coordinate c = (Coordinate) e.nextElement(); res.append(c.x + "," + c.y + ";"); } return new String(res); } }