Advertisement
fosterbl

MagicSquare1.java

Jan 22nd, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. //(c) A+ Computer Science
  2. //www.apluscompsci.com
  3. //Name -
  4.  
  5. import java.util.Scanner;
  6. import static java.lang.System.*;
  7.  
  8. public class MagicSquare1
  9. {
  10.     private int[][] mat;
  11.  
  12.     //size the matrix and load in the numbers into the matrix
  13.     //write all nested loop code here in the constructor
  14.     public MagicSquare1(int size, int[] numbers)
  15.     {
  16.     }
  17.  
  18.    //returns true if all rows, columns, and diagonals add up to the same thing
  19.     public boolean isMagicSquare()
  20.     {
  21.         return false;
  22.     }
  23.  
  24.     public int sumRow( int r )
  25.     {
  26.         return 0;
  27.     }
  28.  
  29.     public int sumCol( int c )
  30.     {
  31.         return 0;
  32.     }
  33.  
  34.     public int sumDownDiag()
  35.     {
  36.         return 0;
  37.     }
  38.  
  39.     public int sumUpDiag()
  40.     {
  41.         return 0;
  42.     }
  43.  
  44.    //returns a String representing the magic square visually
  45.     public String toString()
  46.     {
  47.         String output="";
  48.         return output;
  49.     }
  50.    
  51.    public String magicOrNot()
  52.    {
  53.       if( isMagicSquare() ) return "MAGIC SQUARE";
  54.       else return "NOT A MAGIC SQUARE";
  55.    }
  56.    
  57.    public static void main(String[] args){
  58.       MagicSquare1 square = new MagicSquare1(3, new int[]{8, 1, 6, 3, 5, 7, 4, 9, 2});
  59.       System.out.println( square + "\n" + square.magicOrNot() );
  60.      
  61.       square = new MagicSquare1(3, new int[]{6, 1, 8, 7, 5, 3, 2, 9, 4});
  62.       System.out.println( square + "\n" + square.magicOrNot() );
  63.      
  64.       square = new MagicSquare1(3, new int[]{8, 3, 1, 3, 5, 7, 9, 4, 2});
  65.       System.out.println( square + "\n" + square.magicOrNot() );
  66.      
  67.       square = new MagicSquare1(4, new int[]{7, 12, 1, 14, 2, 13, 8, 11, 16, 3, 10, 5, 9, 6, 15, 4});
  68.       System.out.println( square + "\n" + square.magicOrNot() );
  69.      
  70.       square = new MagicSquare1(5, new int[]{17, 24, 1, 8, 15, 23, 5, 7, 14, 16, 4, 6, 13, 20, 22, 10, 12, 19, 21, 3, 11, 18, 25, 2, 9});
  71.       System.out.println( square + "\n" + square.magicOrNot() );
  72.      
  73.       square = new MagicSquare1(5, new int[]{17, 24, 1, 8, 5, 23, 5, 7, 14, 6, 4, 6, 13, 20, 2, 10, 12, 19, 21, 3, 11, 18, 25, 2, 9});
  74.       System.out.println( square + "\n" + square.magicOrNot() );      
  75.    }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement