Rough illustration on how to compare x and y coordinates from a list of coordinates against some min and max

In [12]:
import java.util.ArrayList;

ArrayList<int[]> list = new ArrayList<int[]> ();

list.add(new int[] {1,2});
list.add(new int[] {3,4});

int xmin = 0; 
int ymin = 0;

for(int i = 0; i < list.size(); i++) {
    int[] el = list.get(i);
    if(list.get(i)[0] < xmin) {
        ...
    }
    if(list.get(i)[1] < ymin) {
        ....
    }
    
}
illegal start of expression
 ...
 ^   

illegal start of expression
 ....
 ^    

Rough illustration on what Ant.next() has to do

In [2]:
int xpos = 0;
int ypos = 0;
final String[] states = { "FaceUp", "FaceDown", "FaceLeft", "FaceRight"}; 
String state = "FaceUp";
InfiniteBlockWorld w;

public static final int UP = 0;

public enum Direction {
    North,
    South,
    West,
    East
}


public void next() {
    Boolean color = w.getCellColor(xpos, ypos);
    String newState;
    Boolean newColor;
    Direction d;
    state = newState;
    w.setCellColor(xpos, ypos, newColor);
    switch(d) {
        case North:
            ypos --;
    }
}
illegal start of expression
 public static final int UP = 0
 ^                              

class, interface, or enum expected
 }
 ^ 
In [10]:
/* illustration of how to return multiple values from a method in Java */
package lecture;

public class Returned {
    
    /* data object used to store cal */
    public static class PersonCal {
        String name;
        int cals;
        public PersonCal(String name, int cals) {
            this.name = name;
            this.cals = cals;
        }
        
        public String toString() {
            return "PersonCal("  + name + "," + cals + ")";
        }
    }
    
    /* return both Person name (String) and calories (Integer) as an Object[] */
    public static Object[] getPersonCal() {
        String name = "asdasdas";
        int cals = 1235;
        Object[] ret;
        
        ret = new Object[2];
        ret[0] = name;
        ret[1] = new Integer(cals);
        return ret;
    }
    
    /* return both Person name and calories as a "data" object */
    public static PersonCal getPersonCalObject() {
        String name = "asdasdas";
        int cals = 1235;
        return new PersonCal(name, cals);
    }
    
    public static void main() {
        Object[] result = Returned.getPersonCal();
        String name = (String) result[0];
        Integer cals = (Integer) result[1];
        System.out.println(String.format("%s %d", name, cals));
        
        PersonCal p = getPersonCalObject();
        System.out.println(p.toString());
    }
}
Out[10]:
lecture.Returned
In [11]:
import lecture.Returned;

Returned.main();
asdasdas 1235
PersonCal(asdasdas,1235)
Out[11]:
null
In [ ]: