CSE 142 Final Cheat Sheet

 

Math Method

Description

 

Random Method

Description

Math.abs(value)

absolute value

 

nextInt(max)

random integer from 0 to max-1

Math.min(v1, v2)

smaller of two values

 

Construction Examples

Math.max(v1, v2)

larger of two values

 

int[] data = new int[10];

Math.round(value)

nearest whole number

 

Random r = new Random();

Math.pow(b, e)

b to the e power

 

Types: ArrayList<String>, ArrayList<Integer>

 

String Method

Description

contains(str)

true if this string contains the other's characters inside it

endsWith(str), startsWith(str)

true if this string starts/ends with the other's characters

equals(str)

true if this string is the same as str

equalsIgnoreCase(str)

true if this string is the same as str, ignoring capitalization

indexOf(str)

index in this string where given string begins (-1 if not found)

length()

number of characters in this string

substring(i, j)

characters in this string from index i (inclusive) to j (exclusive)

toLowerCase(), toUpperCase()

a new string with all lowercase or uppercase letters

charAt(i)

returns char at index i

 

Scanner Method

Description

nextInt(), hasNextInt()

read/return token as int and test if reading will succeed

next(), hasNext()

read/return token as String and test if reading will succeed

nextDouble(), hasNextDouble()

read/return token as double and test if reading will succeed

nextLine(), hasNextLine()

read/return line as String and test if reading will succeed

 

ArrayList Method

Description

add(value)

appends value at end of list

add(index, value)

inserts given value at given index, shifting subsequent values right

clear()

removes all elements of the list

get(index)

returns the value at given index

remove(index)

removes/returns value at given 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 classes

public class name extends Critter {

    fields/constructor

 

    public Color getColor() {

        statement(s) that return a Color (e.g., Color.RED, Color.BLUE, Color.GREEN)

    }

   

    public Action getMove(CritterInfo info) {

        statement(s) that return Action.INFECT, Action.HOP, Action.RIGHT, or Action.LEFT

    }

   

    public String toString() {

        statement(s) that return a String;

    }

}

 

CritterInfo Method

Description

getFront(), getBack(), getLeft(), getRight()

returns one of Neighbor.WALL, Neighbor.EMPTY, Neighbor.SAME, Neighbor.OTHER

getDirection()

returns one of Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST