2013-04-22 2 views
-2

나는 코드 작성에 문제가있다. 스도쿠 보드 검사기를 만들어야합니다. 목표는 모든 메소드를 검사하고 통과하면 true를 리턴하는 public boolean checkAll()을 사용해야하는 5 가지 특정 메소드를 사용하여 Sudoku 클래스를 확장하는 것입니다 (CheckableSudoku 클래스를 만들기 위해). Heres 내 코드! 내가 너무 혼동이 설명하는 경우 죄송합니다 :/스도쿠 검사기 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

+0

그리고 귀하의 질문은 무엇입니까? –

답변

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; 
} 

지금까지 어쨌든 모든 방법이 사실로 돌아가는 것 같습니다. 확실한 예인지 아닌지는 확실치 않습니다. 그렇지 않다면 논리를 점검해야합니다.