0.0 General‎ > ‎Assignments‎ > ‎Magic Squares‎ > ‎

### Magic Squares: OOPs

This is a framework you can use to implement magic squares in an OOPs environment:

### Class: Cell

#### Cell Attributes:

 Attribute Data Type Scope Purpose row integer - private the row the cell is in column integer - private the column the cell is in isOccupied boolean - private indicates if the cells contains a value. set to false when created value integer - private the integer value of the cell in the magic square

#### Cell Methods:

 Method Return Type Scope Purpose Cell( int r,    int c) + public Constructor: sets isOccuppied to false, row to r, col to c isOccupied() boolean + public return the current value of isOccupied setValue(    int value) void + public set the value of the cell getValue() int + public return the current cell value

### Class: MagicSquare

#### Square Attributes:

 Attribute Data Type Scope Purpose mSquare Cell [][] - private a 2D array to hold the magic square size int - private the size of the magic square startValue int - private the first number start value in the square step int - private the amount to change each new value in the magic square

#### Square Methods:

 Method Return Type Scope Purpose Square() + public Constructor: set the default values square(    int size,     int start,    int step) void - private called by the constructors to create the magic square initsquare() void used by: square() creates mSquare full of empty cells setValues() void - private used by: square()  sets the values in magic square displaySquare() void - private used by: square()  will display the square neatly on the screen nextCell(  Cell currentCell) Cell - private return the next cell to be occupiedused by: setValues() nextValue(    int x) int - private returns the next value to be placed in a cellused by: setValues()