Baby Sitter Kata

  • Babysitter can work from 5pm-4am
  • The pay rate from start time to bed time is 12 per hour.
  • The pay rate from bed time to midnight is 8 per hour.
  • The pay rate from midnight to 4am is 16 per hour.
  • The sitter charges for full hours.

jUnit Test

Java


              package babysitterkata;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Rob
 */
public class BabySitterTest {

    public BabySitterTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {

    }

    @After
    public void tearDown() {
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    // The Urge to DDT TDD is great.
    // @Test
    // public void hello() {}
    @Test
    public void isValidStartTimeTest() {
        BabySitter baby = new BabySitter();

        assertEquals(false, baby.isValidStartTime(-10)); //way outside
        assertEquals(false, baby.isValidStartTime(0));  // it's zero
        assertEquals(false, baby.isValidStartTime(4)); //just outside
        assertEquals(true, baby.isValidStartTime(5)); //boundary
        assertEquals(true, baby.isValidStartTime(6)); //just inside
        assertEquals(true, baby.isValidStartTime(10)); //middle type value
        assertEquals(true, baby.isValidStartTime(12)); //cause it's midnight, it's special
        assertEquals(true, baby.isValidStartTime(15)); //last hour available to start
        assertEquals(false, baby.isValidStartTime(16)); //boundary
        assertEquals(false, baby.isValidStartTime(17)); //just outside
        assertEquals(false, baby.isValidStartTime(2015)); //waaaay outside

    }

    @Test
    public void isValidBedTimeTest() {
        BabySitter baby = new BabySitter();
        assertEquals(false, baby.isValidBedTime(-10)); //way outside
        assertEquals(false, baby.isValidBedTime(0));  // it's zero
        assertEquals(false, baby.isValidBedTime(4)); //just outside
        assertEquals(true, baby.isValidBedTime(5)); //boundary
        assertEquals(true, baby.isValidBedTime(6)); //just inside
        assertEquals(true, baby.isValidBedTime(10)); //middle type value
        assertEquals(true, baby.isValidBedTime(12)); //cause it's midnight, it's special
        assertEquals(true, baby.isValidBedTime(15)); //just inside
        assertEquals(true, baby.isValidBedTime(16)); //boundary
        assertEquals(false, baby.isValidBedTime(17)); //just outside
        assertEquals(false, baby.isValidBedTime(2015)); //waaaay outside

    }

    @Test
    public void isValidEndTimeTest() {
        BabySitter baby = new BabySitter();
        assertEquals(false, baby.isValidEndTime(-10)); //way outside
        assertEquals(false, baby.isValidEndTime(0));  // it's zero
        assertEquals(false, baby.isValidEndTime(4)); //just outside
        assertEquals(false, baby.isValidEndTime(5)); //boundary
        assertEquals(true, baby.isValidEndTime(6)); //just inside
        assertEquals(true, baby.isValidEndTime(10)); //middle type value
        assertEquals(true, baby.isValidEndTime(12)); //cause it's midnight, it's special
        assertEquals(true, baby.isValidEndTime(15)); //just inside
        assertEquals(true, baby.isValidEndTime(16)); //boundary
        assertEquals(false, baby.isValidEndTime(17)); //just outside
        assertEquals(false, baby.isValidEndTime(2015)); //waaaay outside
    }

    @Test
    public void isValidTimeTest() {
        BabySitter baby = new BabySitter();
        assertEquals(false, baby.isValidTime(-10)); //way outside
        assertEquals(false, baby.isValidTime(0));  // it's zero
        assertEquals(false, baby.isValidTime(-1)); //just outside
        assertEquals(true, baby.isValidTime(1)); //boundary
        assertEquals(true, baby.isValidTime(2)); //just inside
        assertEquals(true, baby.isValidTime(10)); //middle type value
        assertEquals(true, baby.isValidTime(11)); //just inside
        assertEquals(true, baby.isValidTime(12)); //boundary
        assertEquals(false, baby.isValidTime(13)); //just outside
        assertEquals(false, baby.isValidTime(2015)); //waaaay outside

    }

    @Test
    public void timeAdjustTest() {
        BabySitter baby = new BabySitter();
        assertEquals(13, baby.timeAdjust(1));
        assertEquals(14, baby.timeAdjust(2));
        assertEquals(16, baby.timeAdjust(4));
        assertEquals(8, baby.timeAdjust(8));
        assertEquals(5, baby.timeAdjust(5));
        assertEquals(12, baby.timeAdjust(12));
        assertEquals(-32, baby.timeAdjust(-44));
    }

    @Test
    public void startToBedDurationConverterTest() {
        BabySitter baby = new BabySitter();

        assertEquals(6, baby.startToBedDurationConverter(5, 12, 11)); //bed after end
        assertEquals(1, baby.startToBedDurationConverter(5, 6, 6)); //double bed and end
        assertEquals(7, baby.startToBedDurationConverter(5, 12, 16)); //range
        assertEquals(0, baby.startToBedDurationConverter(12, 13, 16)); //more testing
        assertEquals(4, baby.startToBedDurationConverter(8, 12, 12)); //lots of 12
        assertEquals(0, baby.startToBedDurationConverter(13, 8, 13)); //start and end past 12
        assertEquals(0, baby.startToBedDurationConverter(5, 12, 5)); //same start and end
        assertEquals(1, baby.startToBedDurationConverter(7, 16, 8)); //bed after both
        assertEquals(1, baby.startToBedDurationConverter(5, 6, 12)); //more variety
        assertEquals(2, baby.startToBedDurationConverter(5, 7, 11)); //more variety
        assertEquals(2, baby.startToBedDurationConverter(8, 10, 13)); //more variety
        assertEquals(2, baby.startToBedDurationConverter(9, 11, 14)); //more variety
        assertEquals(0, baby.startToBedDurationConverter(5, 5, 6)); //double bed and end
        assertEquals(7, baby.startToBedDurationConverter(5, 16, 16)); //double bed and end

    }

    @Test
    public void bedToMidnightDurationConverterTest() {
        BabySitter baby = new BabySitter();
        assertEquals(0, baby.bedToMidnightDurationConverter(5, 12, 11)); //bed after end
        assertEquals(0, baby.bedToMidnightDurationConverter(5, 6, 6)); //double bed and end
        assertEquals(0, baby.bedToMidnightDurationConverter(5, 12, 16)); //range
        assertEquals(0, baby.bedToMidnightDurationConverter(12, 13, 16)); //more testing
        assertEquals(0, baby.bedToMidnightDurationConverter(8, 12, 12)); //lots of 12
        assertEquals(0, baby.bedToMidnightDurationConverter(13, 8, 13)); //start and end past 12
        assertEquals(0, baby.bedToMidnightDurationConverter(5, 12, 5)); //same start and end
        assertEquals(0, baby.bedToMidnightDurationConverter(7, 16, 8)); //more variety
        assertEquals(2, baby.bedToMidnightDurationConverter(5, 6, 8)); //more variety
        assertEquals(6, baby.bedToMidnightDurationConverter(5, 6, 12)); //more variety
        assertEquals(4, baby.bedToMidnightDurationConverter(5, 7, 11)); //more variety
        assertEquals(2, baby.bedToMidnightDurationConverter(8, 10, 13)); //more variety
        assertEquals(1, baby.bedToMidnightDurationConverter(9, 11, 14)); //more variety
        assertEquals(1, baby.bedToMidnightDurationConverter(5, 5, 6)); //double bed and end
        assertEquals(0, baby.bedToMidnightDurationConverter(5, 16, 16)); //double bed and end

    }

    @Test
    public void midnightToEndDurationConverterTest() {
        BabySitter baby = new BabySitter();
        assertEquals(0, baby.midnightToEndDurationConverter(5, 12, 11)); //bed after end
        assertEquals(0, baby.midnightToEndDurationConverter(5, 6, 6)); //double bed and end
        assertEquals(4, baby.midnightToEndDurationConverter(5, 12, 16)); //range
        assertEquals(4, baby.midnightToEndDurationConverter(12, 13, 16)); //more testing
        assertEquals(0, baby.midnightToEndDurationConverter(8, 12, 12)); //lots of 12
        assertEquals(0, baby.midnightToEndDurationConverter(13, 8, 13)); //start and end past 12
        assertEquals(0, baby.midnightToEndDurationConverter(5, 12, 5)); //same start and end
        assertEquals(0, baby.midnightToEndDurationConverter(7, 16, 8)); //more variety
        assertEquals(0, baby.midnightToEndDurationConverter(5, 6, 8)); //more variety
        assertEquals(0, baby.midnightToEndDurationConverter(5, 6, 12)); //more variety
        assertEquals(0, baby.midnightToEndDurationConverter(5, 7, 11)); //more variety
        assertEquals(1, baby.midnightToEndDurationConverter(8, 10, 13)); //more variety
        assertEquals(2, baby.midnightToEndDurationConverter(9, 11, 14)); //more variety
        assertEquals(0, baby.midnightToEndDurationConverter(5, 5, 6)); //double bed and end
        assertEquals(4, baby.midnightToEndDurationConverter(5, 16, 16)); //double bed and end

    }

    @Test
    public void babySitterPayCalculatorTest() {
        BabySitter baby = new BabySitter();
        assertEquals(3 * baby.startToBedRate + 4 * baby.bedToMidnightRate + 2 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 8, 14));//first test
        assertEquals(0 * baby.startToBedRate + 1 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 5, 6));//1 hour in start no bed time
        assertEquals(0 * baby.startToBedRate + 2 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 5, 7));//2 hours starting at bed time
        assertEquals(2 * baby.startToBedRate + 4 * baby.bedToMidnightRate + 2 * baby.midnightToLateRate, baby.babySitterPayCalulator(6, 8, 14));//start  1 hour late 
        assertEquals(0 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 1 * baby.midnightToLateRate, baby.babySitterPayCalulator(12, 12, 13));//start at midnight
        assertEquals(0 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 4 * baby.midnightToLateRate, baby.babySitterPayCalulator(12, 13, 16));//late night sit
        assertEquals(7 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 4 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 16, 16));//max pay night
        assertEquals(6 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 12, 11));//max pay night
        assertEquals(1 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 6, 6));//max pay night
        assertEquals(7 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 4 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 12, 16));//max pay night
        assertEquals(0 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 4 * baby.midnightToLateRate, baby.babySitterPayCalulator(12, 13, 16));//max pay night
        assertEquals(4 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(8, 12, 12));//max pay night
        assertEquals(0 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(13, 8, 13));//max pay night
        assertEquals(0 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 12, 5));//max pay night
        assertEquals(1 * baby.startToBedRate + 0 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(7, 16, 8));//max pay night
        assertEquals(1 * baby.startToBedRate + 2 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 6, 8));//max pay night
        assertEquals(1 * baby.startToBedRate + 6 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 6, 12));//max pay night
        assertEquals(2 * baby.startToBedRate + 2 * baby.bedToMidnightRate + 1 * baby.midnightToLateRate, baby.babySitterPayCalulator(8, 10, 13));//max pay night
        assertEquals(2 * baby.startToBedRate + 1 * baby.bedToMidnightRate + 2 * baby.midnightToLateRate, baby.babySitterPayCalulator(9, 11, 14));//max pay night
        assertEquals(0 * baby.startToBedRate + 1 * baby.bedToMidnightRate + 0 * baby.midnightToLateRate, baby.babySitterPayCalulator(5, 5, 6));//max pay night

    }
}  

 package babysitterkata;

import java.util.Scanner;

/**
 *
 * @author Rob
 */
public class BabySitter {
//start time is stated as 5pm or later so a "2" will be considered 2am and the value will be 14, a value of 0 will be considered midnight.
    //input cannot be greater than 12.

    /**
     * @param args the command line arguments
     */
    int earliestStartTime;
    int maxEndTime;
    int startToBedRate;
    int bedToMidnightRate;
    int midnightToLateRate;
    int userBedTimeInput;
    int userStartInput;
    int userEndInput;

    public BabySitter() {
        this.initBabySitterData();
    }

    private void initBabySitterData() {
        //this method would read different babysitter files and assign values, but here,
        //just going to hard code them.
        this.earliestStartTime = 5;
        this.maxEndTime = 16;
        this.startToBedRate = 12;
        this.bedToMidnightRate = 8;
        this.midnightToLateRate = 16;

    }

    public int babySitterPayCalulator(int userStartInput, int userBedTimeInput, int userEndInput) {
        // System.out.println("entering paycalc start: " + userStartInput + " bed: " + userBedTimeInput + " end: " + userEndInput);
        int startToBedPay;
        int bedToMidnightPay;
        int midnightToEndPay;
        boolean validCheck = false;
        validCheck = this.isValidTime(userStartInput);

        startToBedPay = this.startToBedDurationConverter(userStartInput, userBedTimeInput, userEndInput) * this.startToBedRate;
        bedToMidnightPay = this.bedToMidnightDurationConverter(userStartInput, userBedTimeInput, userEndInput) * this.bedToMidnightRate;
        midnightToEndPay = this.midnightToEndDurationConverter(userStartInput, userBedTimeInput, userEndInput) * this.midnightToLateRate;
        //System.out.println("dur1: " + this.startToBedDurationConverter(userStartInput, userBedTimeInput, userEndInput) + " dur2:" + this.bedToMidnightDurationConverter(userStartInput, userBedTimeInput, userEndInput) + " dur3: " + this.midnightToEndDurationConverter(userStartInput, userBedTimeInput, userEndInput));

        int totalPay = startToBedPay + bedToMidnightPay + midnightToEndPay;
        //System.out.println("paycalc returning " + totalPay);
        return totalPay;
    }

    public int startToBedDurationConverter(int startTime, int bedTime, int endTime) {
        //takes times and returns payrate duration time period for start to bed
        if (startTime >= bedTime) {
            //System.out.println("s2b returning " + "0" + "on path 1");
            return 0;
        }
        if (startTime >= 12) {
            //System.out.println("s2b returning 0 on path 2");
            return 0;
        }
        //eg. if start at 5 and end at 11 but bedtime is 12 then p1 hours are 6
        if (endTime <= bedTime) {
            if (endTime >= 12) {
                //System.out.println("s2b returning " + 12 - startTime + " on path 3");
                return 12 - startTime;
            } else {
                // System.out.println("s2b returning " + endTime-startTime + "on path 4");
                return (endTime - startTime);
            }
        } else {
            if (bedTime >= 12) {
                // System.out.println("s2b returning " + 12- startTime+ "on path 5");
                return 12 - startTime;
            } else {
                //  System.out.println("s2b returning " + bedTime-startTime + " on path 6");
                return bedTime - startTime;
            }
        }
    }

    public int bedToMidnightDurationConverter(int startTime, int bedTime, int endTime) {
        //takes times and returns payrate duration time period for bed to midnight
        if (startTime > bedTime
                || bedTime >= 12
                || startTime >= 12
                || endTime <= bedTime) {
            //System.out.println("b2m returning 0 on path 1");
            return 0;
        }
        if (endTime <= 12) {
            // System.out.println("b2m returning" + endTime-bedTime + "on path 2");
            return endTime - bedTime;
        }
        if (bedTime <= 12) {
            // System.out.println("b2m returning " + 12-bedTime + "on path 3");
            return 12 - bedTime;
        }
        // System.out.println("b2m returning 0 because it skipped everything on all paths");
        return 0;
    }

    public int midnightToEndDurationConverter(int startTime, int bedTime, int endTime) {
        //takes times and returns payrate duration time period for after midnight
        //System.out.println("entering m2eduration start: " + startTime + " bed: " + bedTime + " end: " + endTime);
        if (endTime <= 12) {
            //System.out.println("m2e returning 0 on path 1");
            return 0;
        }
        if (startTime == endTime) {
//            System.out.println("m2e returning 0 on path 2");
            return 0;
        }
        if (endTime >= 12) {
            //System.out.println("m2e returning "+ endTime-12 +" on path 3");
            return endTime - 12;
        }
//        System.out.println("m2e returning crazy 5000 on path 4");
        return 5000;
    }

    public boolean isValidTime(int time) {
        //making sure time entered is within valid range
        //System.out.println("time check");
        return !(time <= 0 || time > 12);
    }

    public int timeAdjust(int time) {
//convert time to workable value by adding 12 to anything less than 4
//        System.out.println("entering TA");
        if (time <= 4) {
            time = time + 12;
        }
//        System.out.println("TA returning "+ time);
        return time;
    }

    public boolean isValidStartTime(int userStartInput) {
//        System.out.println("valid start time check");
        return !(userStartInput < this.earliestStartTime || userStartInput >= this.maxEndTime);
    }

    public boolean isValidBedTime(int userBedTimeInput) {
//        System.out.println("valid bed time check");
        return !(userBedTimeInput < this.earliestStartTime || userBedTimeInput > this.maxEndTime);
    }

    public boolean isValidEndTime(int userEndInput) {
//        System.out.println("valid end time check");
        return !(userEndInput <= this.earliestStartTime || userEndInput > this.maxEndTime);
    }

    public static void main(String[] args) {
        BabySitter baby = new BabySitter();
        //tried doing it with 0 libraries per spec, could not figure out how to do it without atleast using scanner
        Scanner sc = new Scanner(System.in);
        boolean isValidEnd = false;
        boolean isValidStart = false;
        boolean isValidBed = false;
        System.out.println("Welcome to Your babysitter pay calculator!");

        while (!isValidStart) {
            System.out.println("Please Enter a Start Time between 5pm-3am");

            while (!sc.hasNextInt()) {
                String input = sc.next();
                System.out.println("Sorry " + input + " is not a valid time, please try again");
            }
            baby.userStartInput = sc.nextInt();
            //System.out.println(baby.userStartInput);
            isValidStart = baby.isValidTime(baby.userStartInput);
            //System.out.println("got here");
            if (isValidStart) {
                baby.userStartInput = baby.timeAdjust(baby.userStartInput);
                isValidStart = baby.isValidStartTime(baby.userStartInput);
                //System.out.println(baby.userStartInput);
            }
        }
        System.out.println("Your Start time value is " + baby.userStartInput);

        while (!isValidBed) {
            System.out.println("Please Enter a bed Time between 5pm-4am");
            while (!sc.hasNextInt()) {
                String input = sc.next();
                System.out.println("Sorry " + input + " is not a valid time, please try again");
            }
            baby.userBedTimeInput = sc.nextInt();
            isValidBed = baby.isValidTime(baby.userBedTimeInput);
            if (isValidBed) {
                baby.userBedTimeInput = baby.timeAdjust(baby.userBedTimeInput);
                isValidBed = baby.isValidBedTime(baby.userBedTimeInput);
            }
        }
        System.out.println("Your bed time value is " + baby.userBedTimeInput);

        while (!isValidEnd) {
            System.out.println("Please Enter a end Time between 6pm-4am");

            while (!sc.hasNextInt()) {
                String input = sc.next();
                System.out.println("Sorry " + input + " is not a valid time, please try again");
            }
            baby.userEndInput = sc.nextInt();
            isValidEnd = baby.isValidTime(baby.userEndInput);
            if (isValidEnd) {
                System.out.println("here");
                baby.userEndInput = baby.timeAdjust(baby.userEndInput);
                isValidEnd = baby.isValidEndTime(baby.userEndInput);
            }
        }
        System.out.println("Your End time value is " + baby.userEndInput);
        int pay = baby.babySitterPayCalulator(baby.userStartInput, baby.userBedTimeInput, baby.userEndInput);
        System.out.println("Your Total Pay for the job is: " + pay);
    }
}

Conway's Game of Life

  • Any live cell with fewer than two live neighbors dies, as if caused by under-population.
  • Any live cell with two or three live neighbors lives on to the next generation.
  • Any live cell with more than three live neighbors dies, as if by over-population.
  • Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

jUnit Test

Java


              package conway;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Rob Helvey
 */
public class ConwayTest {

    public ConwayTest() {
    }

    @BeforeClass
    public static void setUpClass() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of isValidStartSize method, of class Conway.
     */
    @Test
    public void testIsValidStartSize() {
        System.out.println("isValidStartSize");
        Conway conway = new Conway();
        assertEquals(false, conway.isValidStartSize(-20)); //way outside
        assertEquals(false, conway.isValidStartSize(0));  // it's zero
        assertEquals(false, conway.isValidStartSize(1000)); //way outside
        assertEquals(true, conway.isValidStartSize(1)); //border
        assertEquals(true, conway.isValidStartSize(50));  // middle
        assertEquals(true, conway.isValidStartSize(25)); //border
    }

    /**
     * Test of isValidEndSize method, of class Conway.
     */
    @Test
    public void testIsValidEndSize() {
        System.out.println("isValidEndSize");
        Conway conway = new Conway();
        assertEquals(false, conway.isValidEndSize(-20)); //way outside
        assertEquals(false, conway.isValidEndSize(0));  // it's zero
        assertEquals(false, conway.isValidEndSize(1000)); //way outside
        assertEquals(true, conway.isValidEndSize(1)); //border
        assertEquals(true, conway.isValidEndSize(50));  // middle
        assertEquals(true, conway.isValidEndSize(25)); //border
    }

    /**
     * Test of isValidSize method, of class Conway.
     */
    @Test
    public void testIsValidSize() {
        System.out.println("isValidSize");
        Conway conway = new Conway();
        assertEquals(false, conway.isValidSize(-20)); //way outside
        assertEquals(false, conway.isValidSize(0));  // it's zero
        assertEquals(false, conway.isValidSize(1000)); //way outside
        assertEquals(true, conway.isValidSize(1)); //border
        assertEquals(true, conway.isValidSize(50));  // middle
        assertEquals(true, conway.isValidSize(25)); //border
    }

    /**
     * Test of life method, of class Conway.
     */
    @Test
    public void testLife() {
        System.out.println("life");

        String[] dish1
                =
                {
                    "...o....",
                    "...oo...",
                    "...o....",
                    "...oo...",
                    "...o....",
                    "...o..o.",
                };
        String[] expResult1
                =
                {
                    "...oo...",
                    "..ooo...",
                    "..o.....",
                    "..ooo...",
                    "..oo....",
                    "........"
                };
        String[] result1 = Conway.life(dish1);
        assertArrayEquals(expResult1, result1);

        String[] dish2
                =
                {
                    "...oo...",
                    "..ooo...",
                    "..o.....",
                    "..ooo...",
                    "..oo....",
                    "........"
                };
        String[] expResult2
                =
                {
                    "..o.o...",
                    "..o.o...",
                    ".o......",
                    ".o..o...",
                    "..o.o...",
                    "........"
                };
        String[] result2 = Conway.life(dish2);
        assertArrayEquals(expResult2, result2);

        String[] dish3
                =
                {
                    "..o.o...",
                    "..o.o...",
                    ".o......",
                    ".o..o...",
                    "..o.o...",
                    "........"
                };
        String[] expResult3
                =
                {
                    "........",
                    ".oo.....",
                    ".ooo....",
                    ".ooo....",
                    "...o....",
                    "........"
                };
        String[] result3 = Conway.life(dish3);
        assertArrayEquals(expResult3, result3);

    }

    /**
     * Test of getNeighbors method, of class Conway.
     */
    @Test
    public void testGetNeighbors() {
        System.out.println("getNeighbors");
        String above = "";
        String same = "";
        String below = "";
        int expResult = 0;
        int result = Conway.getNeighbors(above, same, below);
        assertEquals(expResult, result);

        assertEquals(3, Conway.getNeighbors("o", "o", "o"));
        assertEquals(0, Conway.getNeighbors(".", ".", "."));
        assertEquals(1, Conway.getNeighbors(".", ".", "o"));
        assertEquals(2, Conway.getNeighbors(".", "o", "o"));
        assertEquals(2, Conway.getNeighbors("o", "o", "."));
        assertEquals(1, Conway.getNeighbors("o", ".", "."));
        assertEquals(1, Conway.getNeighbors(".", "o", "."));
        assertEquals(2, Conway.getNeighbors("o", ".", "o"));

    }

}

 package conway;

import java.util.Scanner;

/**
 *
 * @author Rob Helvey
 */
public class Conway {

    public int userStartSize;
    public int userEndSize;
    public int smallestStartSize = 1;
    public int largestEndSize = 50;

    public boolean isValidStartSize(int userStartSize) {
        return !(userStartSize < this.smallestStartSize || userStartSize > this.largestEndSize);
    }

    public boolean isValidEndSize(int userEndSize) {
        //for optional grid sizing to be done later
        return !(userEndSize < this.smallestStartSize || userEndSize > this.largestEndSize);
    }

    public boolean isValidSize(int size) {
        //for optional grid sizing to be done later
        return !(size <= 0 || size > 50);
    }

    public static void main(String[] args) {
        Conway conway = new Conway();
        boolean isValidStartSize = false;
        boolean isValidEndSize = false;
        boolean isValidSize = false;

        Scanner sc = new Scanner(System.in);

        System.out.println("Welcome to Rob's version of Conway's Game of Life!");

        while (!isValidStartSize)
        {
            {
                System.out.println("Please Enter how many generations you want to see(between 0-50)");

                while (!sc.hasNextInt())
                {
                    String input = sc.next();
                    System.out.println("Sorry " + input + " is not a valid size, please try again");
                }
                conway.userStartSize = sc.nextInt();
                isValidStartSize = conway.isValidSize(conway.userStartSize);
                if (isValidStartSize)
                {
                    isValidStartSize = conway.isValidSize(conway.userStartSize);
                }
            }
            System.out.println("Number of generations choosen: " + conway.userStartSize);

        }
        String[] dish =
        {
            "...o....",
            "...oo...",
            "...o....",
            "...oo...",
            "...o....",
            "...o..o.",
        };
        int gens = conway.userStartSize + 1;
        for (int i = 0; i < gens; i++)
        {
            System.out.println("Generation " + i + ":");
            print(dish);
            dish = life(dish);
        }
    }

    public static String[] life(String[] dish) {
        String[] newGen = new String[dish.length];
        for (int row = 0; row < dish.length; row++)
        {
            newGen[row] = "";
            for (int i = 0; i < dish[row].length(); i++)
            {
                String above = "";
                String same = "";
                String below = "";
                if (i == 0)
                {
                    above = (row == 0) ? null : dish[row - 1].substring(i,
                            i + 2);
                    same = dish[row].substring(i + 1, i + 2);
                    below = (row == dish.length - 1) ? null : dish[row + 1]
                            .substring(i, i + 2);
                } else if (i == dish[row].length() - 1)
                {
                    above = (row == 0) ? null : dish[row - 1].substring(i - 1,
                            i + 1);
                    same = dish[row].substring(i - 1, i);
                    below = (row == dish.length - 1) ? null : dish[row + 1]
                            .substring(i - 1, i + 1);
                } else
                {
                    above = (row == 0) ? null : dish[row - 1].substring(i - 1,
                            i + 2);
                    same = dish[row].substring(i - 1, i)
                            + dish[row].substring(i + 1, i + 2);
                    below = (row == dish.length - 1) ? null : dish[row + 1]
                            .substring(i - 1, i + 2);
                }
                int neighbors = getNeighbors(above, same, below);
                if (neighbors < 2 || neighbors > 3)
                {
                    newGen[row] += ".";
                } else if (neighbors == 3)
                {
                    newGen[row] += "o";
                } else
                {
                    newGen[row] += dish[row].charAt(i);
                }
            }
        }
        return newGen;
    }

    public static int getNeighbors(String above, String same, String below) {
        int ans = 0;
        if (above != null)
        {
            for (char x : above.toCharArray())
            {
                if (x == 'o')
                {
                    ans++;
                }
            }
        }
        for (char x : same.toCharArray())
        {
            if (x == 'o')
            {
                ans++;
            }
        }
        if (below != null)
        {
            for (char x : below.toCharArray())
            {
                if (x == 'o')
                {
                    ans++;
                }
            }
        }
        return ans;
    }

    public static void print(String[] dish) {
        for (String s : dish)
        {
            System.out.println(s);
        }
    }
}