1 /*************************************************************************
2 * Compilation: javac Cell.java
6 *************************************************************************/
9 private boolean spin; // up (true) or down (false)
11 public Cell(boolean spin) {
15 // random spin - up with probability p
16 public Cell(double p) {
17 spin = (Math.random() < p);
21 public void flip() { spin = !spin; }
23 // +1 if up, -1 if down
24 public double magnetization() {
25 if (spin) return +1.0;
29 // draw cell according to value of spin
30 public void draw(double x, double y) {
32 if (spin) StdDraw.setPenColor(StdDraw.WHITE);
33 else StdDraw.setPenColor(StdDraw.BLUE);
34 StdDraw.filledSquare(x, y, 1);
38 // string representation
39 public String toString() {
46 public static void main(String[] args) {