2013-04-22 68 views
-2

我对使用我正在编写的代码时遇到的问题有疑问。我需要创建一个数独棋盘检查器。目标是通过使用5个特定的方法来扩展Sudoku类(使CheckableSudoku类),我必须使用public boolean checkAll()来检查所有的方法,如果它们通过则返回true。继承人我的代码!很抱歉,如果我解释说这也太容易混淆:/Sudoku Checker Java

import java.util.Scanner; 
public class CheckableSudoku extends Sudoku 
{ 
    public int getCell(int xColumn, int yRow) 
    { 
     return this.board[xColumn][yRow]; 
    } 

    public boolean checkRow (int yCoord) 
    { 
     int sum = 0; 

     for (int x = 0; x <9; x++) 
     { 
      sum = sum + getCell (x,yCoord); 
     } 
    return(true); 
    } 

    public boolean checkColumn (int xCoord) 
    { 
     int sum = 0; 
     for (int y = 0; y < 9 ;y++) 
     { 
      sum = sum + getCell (xCoord, y); 
     } 
     return(true); 
    } 

    public boolean checkBlock (int col0to2, int row0to2) 
    { 
     int sum = 0; 
     for (int x=0; x<3; x++) 
     { 
      for (int y=0; y<3;y++) 
      { 
       sum = sum + getCell (col0to2+x, row0to2+y); 
      } 
     } 
     return(true); 
    } 

    public boolean checkAll() 
    { 
    // this is the method that checks all the other methods above 
    return true; 
    } 

    public static void main(String[] a) 
    { 
     CheckableSudoku me = new CheckableSudoku(); 
     Scanner sc = new Scanner(System.in); 
     me.read(sc); 
     System.out.print(me); 

     System.out.println(me.checkAll()); 
    } 
} 
+3

什么,具体而言,是你的问题? – Keppil 2013-04-22 21:15:01

+0

而你的问题是? – 2013-04-22 21:51:08

回答

3

这里是你如何可以检查,如果他们都返回一个例子真的还是假的:

public boolean checkAll() { 
    return (method1() && method2() && method3() && method4() && method5()); 
} 

OR:

// Same thing but more typing. 
public boolean checkAll() { 
    if (method1() && method2() && method3() && method4() && method5()) 
     return true; 
    else 
     return false; 
} 

到目前为止无论如何,你所有的方法似乎都会恢复正常。不知道它只是一个例子。如果不是,你需要检查你的逻辑。