Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        4年前关闭。
                                                                                            
                
        
这是我得到的错误:

 airfoilNumber.java:5: error: cannot access airfoil
    private airfoil myAirfoil = new airfoil();
            ^
  bad class file: ./airfoil.class
    class file contains wrong class: airfoil.airfoil
    Please remove or make sure it appears in the correct subdirectory of the classpath.


这是我的主要课程:

    import java.util.Scanner;

public class airfoilNumber
{
    private airfoil myAirfoil = new airfoil();
    public static void main(String[] args)
    {
    Scanner numNaca1 = new Scanner(System.in); //make a scanner and prompt user for their desired NACA number
    System.out.println("What is your NACA number?"); //prompt user for NACA number
    int numNaca = numNaca1.nextInt(); //apply the number to numNaca
    new airfoil(numNaca); //call out airfoil class and run calculations


    }
}


这是我的计算器课:

package airfoil;
import java.text.DecimalFormat;
import java.text.NumberFormat;

public class airfoil

{

    private static final int numOfCoord = 250;
    double dx = 1

.0 / numOfCoord;

private double      m;      // maximum camber in % of chord
private double      p;      // chordwise position of max ord., 10th of chord
private double      t;      // thickness in % of the cord

private String      nacaNum;        // NACA number - 4 digits
private double[][]  coordinates;    // Coordinates of the upper half or lower half of the airfoil
private double[][]  meanLine;       // mean line coordinates

public airfoil(String number) {

    nacaNum = number;
    m = Double.parseDouble(nacaNum.substring(0,1)) / 100.0;
    p = Double.parseDouble(nacaNum.substring(1,2)) / 10.0;
    t = Double.parseDouble(nacaNum.substring(2,4)) / 100.0;

    meanLine = new double[2][numOfCoord];  // x values row 0, y values row 1

    // x upper = row 0,
    // y upper = row 1,
    // x lower = row 2,
    // y lower = row 3
    coordinates = new double [4][numOfCoord];

    System.out.println("NACA: " + nacaNum);
    System.out.println("Number of coordinates: " + numOfCoord);

    calcMeanLine();
    calcAirfoil();

}

/*
 * Calculates the values for the mean line forward of the maximum
 * ordinate and aft of the maximum ordinate.
 */
private void calcMeanLine() {

    double x = dx;
    int j = 0;

    // fwd of max ordinate
    while (x <= p) {
        meanLine[0][j] = x;
        meanLine[1][j] = (m / (p * p))*(2*p*x - (x*x));
        x += dx;
        j++;
    }

    // aft of max ordinate
    while (x <= 1.0 + dx) {
        meanLine[0][j] = x;
        meanLine[1][j] = (m / ((1 - p) * (1 - p))) *
                     ((1 - 2*p) + 2*p*x - x * x);
        x += dx;
        j++;
    }
}  // end calcMeanLine

/*
 * Calculate the upper and lower coordinates of the airfoil surface.
 */
private void calcAirfoil() {

    double theta;       // arctan(dy_dx)
    double dy;          // derivative of mean line equation
    double yt, ml;      // thickness and meanline values, respectively
    double x = dx;      // x-value w.r.t. chord
    int j = 0;          // counter for array

    // calculate upper/lower surface coordinates fwd of max ordinate
    while (x <= p) {

        dy = (m / (p*p)) * (2*p - 2*x);
        theta = Math.atan(dy);
        yt = thicknessEQ(x);
        ml = meanLine[1][j];

        // upper surface coordinates;
        coordinates[0][j] = x - yt * Math.sin(theta);
        coordinates[1][j] = ml + yt * Math.cos(theta);

        // lower surface coordinates
        coordinates[2][j] = x + yt*Math.sin(theta);
        coordinates[3][j] = ml - yt * Math.cos(theta);

        x += dx;
        j++;

    }

    // calculate the coordinates aft of max ordinate
    while (x <= 1.0 + dx) {

        dy = (m / ((1 - p) * (1 - p))) * ((2 * p) - (2 * x));
        theta = Math.atan(dy);

        yt = thicknessEQ(x);
        ml = meanLine[1][j];

        // upper surface coordinates;
        coordinates[0][j] = x - yt * Math.sin(theta);
        coordinates[1][j] = ml + yt * Math.cos(theta);

        // lower surface coordinates
        coordinates[2][j] = x + yt * Math.sin(theta);
        coordinates[3][j] = ml - yt * Math.cos(theta);

        x += dx;
        j++;
    }

    System.out.println("j = " + j);

} // end calcAirfoil

/*
 * Thickness equation
 */
private double thicknessEQ(double x) {

    return ((t / 0.2) * (0.2969 * Math.sqrt(x) - (0.126 * x) -
            (0.3526 * x * x) + (0.28430 * x * x * x) -
            (0.1015 * x * x * x * x)));
}

public String toString() {

    String str = "";
    NumberFormat df = new DecimalFormat("0.0000");

    System.out.println("Xu\tYu\tXl\tYl");

        for (int j = 0; j < numOfCoord; j++) {
            str += df.format(coordinates[0][j]) + "\t" +
                   df.format(coordinates[1][j]) + "\t" +
                   df.format(coordinates[2][j]) + "\t" +
                   df.format(coordinates[3][j]) + "\n";
        }

    return str;
}

/*
 * Return the coordinates array
 */
public double[][] getCoordinates() { return coordinates; }
public int getSize() { return numOfCoord; }

} // end Airfoil class


这是我尝试过的:

到处移动airfoil.class文件以使其正常工作

使用“新翼型(“”);“本身,仍然给我同样的错误

使用任何其他类型的代码来调用我的计算器类,同样的错误。

我不知道还有什么要改变的。我不知道这对我说“错误的机翼。机翼”有什么意义,这也许可以引导我找到解决方案。

我在这里做错了什么?

最佳答案

您具有以下类结构:

package airfoil;

public class airfoil {
   ...
}




public class airfoilNumber {
   ...
}


这需要反映在文件系统上,如下所示:

MyProject                     Project's top level directory
    +-airfoilNumber.java
    +-airfoil                 directory for "airfoil" package
        +-airfoil.java


另外,您还需要在airfoil.airfoil类中导入airfoilNumber

import airfoil.airfoil;

public class airfoilNumber {
}


通过此设置,您可以使用以下命令从项目的顶级目录中编译这两个类:

C:> javac *.java


作为附带说明,类名应以大写字母开头。我保留了问题的名称,因为class定义与其包含的.java文件之间的大小写不匹配可能会导致其他问题,至少在MS Windows上很难跟踪。

完成后,您需要修复airfoil类的构造函数。当前只有一个带有String参数的构造函数,但是您可以按以下方式调用它:

private airfoil myAirfoil = new airfoil();
// does not compile - no non-arg constructor available

...

new airfoil(numNaca);
// does not compile - numNaca is int, constructor expects String

07-28 03:37