Java ----> Game of Life (Abstract Class Version) [3000 points total] if i am sat
ID: 638967 • Letter: J
Question
Java ----> Game of Life (Abstract Class Version) [3000 points total]
if i am satisfied with the work i will provide another link for another 1500 points .....total of 3000 points)
===>>> Implement all the functions that I have and make the program working
In this assignment, you will define two member functions of class Square: bool getLiveInfo() and void update() as pure virtual functions by the "=0" syntax. As a result, class Square will become an abstract class. As we studied in class, no concrete objects can be created through an abstract class. That means that class Square will only serve as a parent class of class Cell. Class Square, however, can be used as a pointer or reference data type of child class objects as "Square * _squares[ROWS][COLS]" in class Grid. In addition, those two pure virtual member functions must be overridden by child class.
Rules:
1) Any live cell with fewer than two live neighbours dies, as if caused by under-population.
2) Any live cell with two or three live neighbours lives on to the next generation.
3) Any live cell with more than three live neighbours dies, as if by overcrowding.
4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
__________
Hints for Game of Life
You don't have to build GUI interface for this simulation unless you are confident with that. I expected command output like the one given in the sample output.
initialize() basically sets up cells on the grid initially
run() starts the simulation run by run (generation by generation)
All parameters are specified in class Param.
Make class Square as an abstract one and class Cell as its child class
A couple of methods in class Square (those virtual ones) need to be abstract methods as well.
The newly calculated state of a cell should not be used for updating its neighbors in the present run.
________________________
public class Grid
{
final class DefineConstants
{
public static final int ROWS = 20;
public static final int COLS = 20;
public static final int NUM_CELLS = 40;
public static final char LIVE_IMAGE = 'O';
public static final char DEAD_IMAGE = '-';
public static final int NUM_RUNS = 10;
public static final int NUM_DISPLAY = 1;
}
/*
//Predeclarations in C++
*
class Square;
class Grid;
class Coordinate;
class Cell;
*/
//__________________________________________________________________
public class Coordinate
{
//Constructors
public Coordinate()
{
_x = 0;
_y = 0;
}
public Coordinate(int x, int y)
{
_x = x;
_y = y;
}
public void dispose()
{
}
public final int getX()
{
return _x;
}
public final int getY()
{
return _y;
}
public final void setX(int anX)
{
_x = anX;
}
public final void setY(int aY)
{
_y = aY;
}
private int _x;
private int _y;
}
//_____________________________________________________________________________
//Class Square serves as an abstract class from which class Cell inherits.
//No concrete objects of Square can be created because of the nature of its abstract
public abstract class Square
{
/*
Square(Grid aGrid, Coordinate aCoord, sbyte aImage);
public void dispose();
sbyte getImage();
Grid getGrid();
void setImage(sbyte NamelessParameter);
Coordinate getCoordinate();
*/
//This function will be overwritten by getLiveInfo() in a child class (Cell)
public abstract boolean getLiveInfo(); //Pure virtual function
//This function will be overwritten by update() in a child class (Cell)
public abstract void update(); //Pure virtual function
private Grid _grid; //The grid to which this square belongs
private Coordinate _coord; //The coordinate of this square on the grid
private byte _image; //Printing form of this object. For example: live cell: O, dead live: -
}
//_____________________________________________________________________________
//Child class
abstract public class Cell extends Square
{
/*
//Constructor of Grid. Initializer will be used to initialize the parent part
Cell(Grid aGrid, Coordinate aCoord, sbyte aImage, int f);
boolean getLiveInfo();
void setLiveInfo(boolean NamelessParameter);
//Count how many live cells among the eight neighbors using the rules
int countLiveNeighbors();
//When a cell becomes dead, _lifeSpan will be reset to zero
void resetLifeSpan();
//If a cell continues to be live during next generation, _lifeSpan will increment by one
void incrementLiveSpan();
//Based on the number of live neighbor cells, update the state of each cell
//for next generation (run) using the rules
void update();
*/
private int _lifeSpan; //The number of generations this cell has lived
private boolean _toBeLive; //True if this cell will be live during next generation
}
//_____________________________________________________________________________
abstract public class grid
{
/*
Grid();
public void dispose();
void initialize();
void run();
void display();
void getStats();
Square getSquare(int x, int y);
void addCells();
*/
private Square[][] _squares = new Square[DefineConstants.ROWS][DefineConstants.COLS]; //A 2D array of pointers to squares (parent class of cells)
}
_________
//GameOfLife.java
public class GameOfLife
{
public static int Main()
{
Grid g = new Grid();
g.initialize();
g.run();
if (g != null)
g.dispose();
// return 0;
}
}
========================================
Output: