CSE142 Final Cheat Sheet
Math Method Description ArrayList Types
-------------------------------------- -----------------
Math.abs(n) absolute value of n ArrayList
Math.max(x, y) maximum of x and y ArrayList
Math.min(x, y) minimum of x and y
Array Construction: int[] data = new int[size];
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 Details
---------------
getMove returns one of Action.HOP, Action.LEFT, Action.RIGHT, Action.INFECT.
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)
public class FlyTrap extends Critter {
public String toString() {
return "T";
}
public Action getMove(CritterInfo info) {
if (info.getFront() == Neighbor.OTHER) {
return Action.INFECT;
} else {
return Action.LEFT;
}
}
public Color getColor() {
return Color.RED;
}
}