CSCI 162 — Lab 1c

Due: Friday September 29, 2017 @ 8:00PM

Life Object

Overview

This lab extends the game of Life assignment that was started in the Life Matrix assignment and continued in the Life Update assignment. You will convert your Life class to allow for the creation of Life objects. These objects are used by interfaces that are available here or through Autolab's handout section. The interfaces provide Console and Graphical views. You should build your new Life methods so that they make use of the already existing functions (e.g., fillMatrix) that you wrote for earlier parts of the Life assignment. This part of the assignment will take the matrix built in the previous assignment and make discrete time increments to advance the state of the game.

Specifications

Your class will provide a constructor of seven parameters:

  1. a seed for the random number generator
  2. the number of rows in the area
  3. the number of columns in the area
  4. the lower bounds of the birth range
  5. the upper bounds of the birth range
  6. the lower bounds of the live range
  7. the upper bounds of the live range

Remember, the seed is of type long while all other parameters are of type int

The constructor should initialize an object that has a matrix filled with random boolean values and RETAINS the ranges for update processing.

The class should provide a method, update, that advances the state by one time unit. This method has no parameters.

The class should provide a method, world, that returns a COPY of the boolean matrix that describes the current state. This method also has no parameters.

The class should STILL OPERATE as in the last assignment when started from the main method of the Life class. e.g. the class is also an executable program

Required Methods (Contract)

public Life (long seed, int rows, int columns,
             int birthLow, int birthHigh,
             int liveLow, int liveHigh)
public void update ()
public boolean[][] world ()

Instructions

You should NOT need to modify the static methods that you wrote for earlier parts of the assignment. You should call them with appropriate parameters. However, if you did not build appropriate methods that do one thing well, you may have to redo your code to include them. Your original program should still work if you run the program starting with the main method in the Life class.

DO NOT MODIFY the downloaded Graphical.java or Console.java. You must modify your implementation of Life.java to meet the requirements expected by these files.

Your Life class must have constructors, accessors, and modifiers that PRECISELY match the requirements of the interfaces (see Required Methods above). Again, YOU MAY NOT MODIFY THE INTERFACE FILES. I will not take these from you when you submit. So your class must precisely interact with these interfaces so my testing will work.

You will need to declare instance variables to hold the matrix and the two ranges (four ints). Your instance methods can then pass them as needed to the static class methods you have previously written.

You can then write the constructor, update, and world methods as described in the Specifications section.

The constructor has parameters that should be checked for validity. Row and column should be at least one. The range values should be between one and nine inclusive. A high value that is less than a low value is LEGAL and specifies an empty range. If a value is not valid, you should throw an IllegalArgumentException with a string that states what the value is and why it is illegal. You can do this with code such as

   throw new IllegalArgumentException("Row must be positive, not " + row);

The world method should return a COPY of the state matrix rather than just return the instance variable so that users of the class cannot modify the world. This is a speed versus strict protection of the representation issue. Java does not provide a mechanism to provide fast access with strict protection.

Check your work. Have you tested your program with both the textual and graphical interface? Did you adhere to the Formatting Requirements? Are parameters clear, appropriate, and minimal? Does each method have a short comment describing what it does and perhaps pre- and post-conditions? Does the program's indenting match its control structure? Do the for loops have appropriate bounds?

Sample Input

6 8
7
3 8
3 8

Sample Output

- -  - - - - - - 
- # # # - - - - 
- # # # # - # - 
- - - # # - # - 
- # - # - # # - 
- - - - - - - - 

- - - - - - - - 
- # # # # - - - 
- # # # # # - - 
- # # # # # # - 
- - # # # # # - 
- - - - - - - - 

- - - - - - - - 
- # # # # # - - 
- # - - # # # - 
- # # - - # # - 
- # # # # # # - 
- - - - - - - - 

- - - - - - - - 
- # # # # # # - 
- # # # # # # - 
- # # # # # # - 
- # # # # # # - 
- - - - - - - - 

- - - - - - - - 
- # # # # # # - 
- # - - - - # - 
- # - - - - # - 
- # # # # # # - 
- - - - - - - - 

- - - - - - - - 
- # # # # # # - 
- # # # # # # - 
- # # # # # # - 
- # # # # # # - 
- - - - - - - - 

Submission

Submit your Life.java file under the Lab 1c: Life Object lab through Autolab

Grading

55 points total