diff --git a/com/laboon/Cell.java b/com/laboon/Cell.java index 1e0eab8..3ed063c 100644 --- a/com/laboon/Cell.java +++ b/com/laboon/Cell.java @@ -67,14 +67,16 @@ public State iterate(int numNeighbors) { * @return Character representation of the cell's state */ - public char getStateRep() { - char toReturn = ' '; - if (_state == State.DEAD) { - toReturn = '.'; - } else if (_state == State.ALIVE) { - toReturn = '*'; - } else { - toReturn = ' '; + public char getStateRep() { + char toReturn = ' '; + if (_state == State.DEAD) { + toReturn = ' '; + } else if (_state == State.ALIVE) { + toReturn = '*'; + } else { + toReturn = ' '; + } + return toReturn; } return toReturn; } diff --git a/com/laboon/JavaLife.java b/com/laboon/JavaLife.java index ed55c86..8431925 100644 --- a/com/laboon/JavaLife.java +++ b/com/laboon/JavaLife.java @@ -2,23 +2,25 @@ public class JavaLife { - /** - * This is the main part. - * - * @param size Size of world - * @param seed Random number seed - * @param percent Percent of cells alive at beginning - * @param maxIterations Maximum number of iterations - */ + /** + * + * @param size Size of a world + * @param seed Random number seed for RNG + * @param percent Percent of cells alive at beginning + * @param maxIterations Maximum number of iterations + */ - public JavaLife(int size, int seed, int percent, int maxIterations) { - World w = new World(size, seed, percent); - System.out.println("Initial Configuration:"); - System.out.println(w.toString()); - for (int j=0; j < maxIterations; j++) { - w = w.iterate(); - System.out.println("Iteration " + (j + 1) + ":"); - System.out.println(w.toString()); + public JavaLife(int size, int seed, int percent, int maxIterations) { + World w = new World(size, seed, percent); + System.out.println("Initial Configuration:"); + System.out.println( w.toString() ); + for (int j=0; j < maxIterations; j++) { + w = w.iterate(); + System.out.println("Iteration " + (j + 1) + ":"); + System.out.println(w.toString()); + } + + } } diff --git a/com/laboon/World.java b/com/laboon/World.java index afd9620..d06be63 100644 --- a/com/laboon/World.java +++ b/com/laboon/World.java @@ -1,6 +1,7 @@ package com.laboon; import java.util.Random; +import java.lang.StringBuilder; public class World { @@ -109,26 +110,26 @@ public World iterate() { return new World(newCells, _rng); } - /** - * Convert this World to a string for display. - * @return String representation of world - */ - - public String toString() { - String toReturn = " "; - for (int j= 0; j < _size; j++) { - toReturn += String.valueOf(j % 10); - } - toReturn += "\n"; - for (int j = 0; j < _size; j++ ) { - toReturn += String.valueOf(j % 10) + " "; - for (int k = 0; k < _size; k++) { - toReturn += (_world[j][k].getStateRep()); - } - toReturn += "\n"; - } - return toReturn; - } + /** + * Convert this World to a string for display. + * @return String representation of world + */ + + public String toString() { + StringBuilder toReturn = new StringBuilder(" "); + for (int j= 0; j < _size; j++) { + toReturn.append(String.valueOf(j % 10)); + } + toReturn.append("\n"); + for (int j = 0; j < _size; j++ ) { + toReturn.append(String.valueOf(j % 10) + " "); + for (int k = 0; k < _size; k++) { + toReturn.append(_world[j][k].getStateRep()); + } + toReturn.append("\n"); + } + return toReturn.toString(); + } /** * Generate initial game board.