以下是我得到的错误:
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文件从一个地方移动到另一个地方以使其工作
使用&#34;新翼型(&#34;&#34;);&#34;本身,仍然给我同样的错误
使用任何其他类型的代码来调出我的计算器类,同样的错误。
我不知道还有什么可以改变的。我不知道它告诉我什么是错误的班级翼型。航空航天&#34;,这可能会引导我找到解决方案。
我在这里做错了什么?
答案 0 :(得分:1)
错误在:
new airfoil(numNaca); //call out airfoil class and run calculations
删除此行并致电:
myAirfoil(numNaca);
新翼型制造你的新实例,而不是运行计算。 代码中存在新实例,请参阅第:行:
private airfoil myAirfoil = new airfoil();
并且访问它是myAirfoil。
答案 1 :(得分:0)
您有以下类结构:
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