我有一个错误:每次从Java测试文件中调用我的Java文件中的一个公共方法时,都会出现“ Java:找不到符号”,但据我所知,没有任何通常的错误会导致此错误错误出现在我的代码中。以下是一些正在访问的Java文件:
import java.io.*;
import java.util.*;
import java.lang.*;
public class SneakyQueens
{
private static final int UO = 0;
// Given an ArrayList of coordinate strings reprsenting the locations of the queens
// on a boardSize x boardSize chess board, return true if none of the queens can
// attack one another. Otherwise, return false.
public static boolean alltheQueensAreSafe(ArrayList<String> coordinateStrings, int boardSize)
{
// maximum number of queens that can still be safe is equal to boardSize because
// none may share a column or row
if (coordinateStrings.size() > boardSize)
return false;
int[] colCo = new int[boardSize + 1];
int[] rowCo = new int[boardSize + 1];
// parsing each element of the ArrayList and evaluating column and diagonal
// values as they are stored
for (String co : coordinateStrings)
{
int colVal = parseCoordinateString(co, 1);
int rowVal = parseCoordinateString(co, 0);
// if column is unoccupied, place flag in column coordinates array
if (colCo[colVal] == UO)
{
colCo[colVal] = 1;
}
else
{
return false;
}
这是一些尝试访问SneakyQueens.java的测试文件
import java.io.*;
import java.util.*;
public class TestCase02
{
private static void checkTest(boolean success)
{
System.out.println(success ? "Hooray!" : "fail whale :(");
}
public static void main(String [] args)
{
ArrayList<String> list = new ArrayList<String>();
list.clear();
list.add("a1");
list.add("b2");
checkTest(SneakyQueens.allTheQueensAreSafe(list, 60000) == false);
list.clear();
list.add("a2");
list.add("b1");
checkTest(SneakyQueens.allTheQueensAreSafe(list, 60000) == false);
list.clear();
list.add("xx342");
list.add("xy343");
checkTest(SneakyQueens.allTheQueensAreSafe(list, 60000) == false);
答案 0 :(得分:0)
您似乎没有使用软件包,这可能解释了为什么您无法从“外部”访问SneakyQueen。
如果您不声明或不想声明SneakyQueen的实例,则应使其抽象化。