CSE142 Final Cheat Sheet Math Method Description -------------------------------------- Math.abs(n) absolute value of n Math.max(x, y) maximum of x and y Math.min(x, y) minimum of x and y String Method Description ----------------------------------------------------------------------------- charAt(index) character at a specific index endsWith(text) whether or not string ends with text equals(text) whether or not string equals text equalsIgnoreCase(text) whether or not string equals text ignoring case indexOf(text) index of a particular string (-1 if not found) length() number of characters in string startsWith(text) whether or not string starts with text substring(start, stop) characters from start (inclusive) to stop (exclusive) substring(start) characters from start to end of string toLowerCase() a new String with lowercase version of original toUpperCase() a new String with uppercase version of original ArrayList method Description ------------------------------------------------------------------------------- add(value) appends value at end of list add(index, value) inserts value at index, shifting subsequent values right clear() removes all elements of the list contains(value) whether the list contains the value get(index) returns the value at given index isEmpty() whether list is empty remove(index) removes value at index, shifting subsequent values left set(index, value) replaces value at given index with given value size() returns the number of elements in list Critter Method Description ----------------------------------------------------------------------------- getMove(CritterInfo info) this critter's next move (one of Action.HOP, Action.LEFT, Action.RIGHT, Action.INFECT) toString() text to display for this critter getColor() color to use for this critter (e.g., Color.BLUE) CritterInfo Class ----------------- There are methods for finding out what kind of critters are around a critter (one of Neighbor.WALL, Neighbor.EMPTY, Neighbor.SAME, Neighbor.OTHER): getFront(), getBack(), getLeft(), getRight() There is a method getDirection() to find out what direction a critter is facing (one of Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST) Syntax Examples: ---------------- for (int i = 1; i <= n; i++) { while (n < 200) { System.out.println("****"); n = n * 2; } } if (n < 0) { System.out.println("negative"); if (n < 0) { } else { System.out.println("negative"); System.out.println("not negative"); } }
Stuart Reges
Last modified: Tue Mar 15 12:02:54 PDT 2011