Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- ////package magicsquare;
- /**
- *
- * @author kelley
- */
- public class MagicSquare {
- //instance variable called data
- //should be a 2d array!
- //will hold the final state of the magicsquare
- //matrix
- int [][] data;
- //should set data 2d array
- //should set data 2d array to
- //3x3 magicsquare
- //NO HARDCODING, Should be enerated by
- //computemagicSquare
- //non-default constructor --> has param
- //accepts a size n for the ODD
- public MagicSquare(){
- }
- //non-default
- //accepts a size n for the ODD
- public void computemagicsquare (int n){
- int [][] square = new int [n][n];
- //Start number 1 in the top row, middle column.
- int row = n;
- int col = n/2;
- int number = 1;
- //Place consecutive integers in a diagonally-up-to-the-right pattern.
- row = row - 1;
- col = col + 1;
- //Any number that goes outside the matrix above row 1
- //is moved to the bottom row.
- //n is the S I Z E
- if (row < 0){
- row = n - 1;
- }
- //Any number that goes outside the matrix past the
- //right column is moved to the left column.
- if (col < 0){
- col = n - 1;
- }
- //Any number, which follows the multiple of the matrix size
- //is moved down 1 row.
- if (jklfjdklajfadkl;jdas;%n = 0){
- row = n - 1;
- }
- }
- public void getData(){
- return array;
- }
- public boolean checkRows(int[][] arr){
- }
- public boolean checkColumns(int[][] arr){
- }
- public boolean checkDiagonals(int[][] arr){
- }
- public void displayMagicSquare(int[][] arr){
- }
- public void checkMagicSquare(int[][] arr){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement