我试过运行它,但打印出来的circleCounter
只打印 0。如果我将计数器代码放在底部的测试器功能下,那么它会起作用。我究竟做错了什么?我错过了什么吗?
public class Project1 {
public int circleCounter; // Number of non-singular circles in the file.
public int posFirstLast; // Indicates whether the first and last circles overlap or not.
public double maxArea; // Area of the largest circle (by area).
public double minArea; // Area of the smallest circle (by area).
public double averageArea; // Average area of the circles.
public double stdArea; // Standard deviation of area of the circles.
public double medArea; // Median of the area.
public int stamp = 189375;
public Project1() {
// This method is complete.
}
public void results(String fileName) {
MaInput F1 = new MaInput("DataFile.data");
double x, y, rad;
int circleCounter = 0;
double sumArea = 0;
Circle A = new Circle();
while (!F1.atEOF()) {
x = F1.readDouble();
y = F1.readDouble();
rad = F1.readDouble();
circleCounter++;
if (A.area() > maxArea) {
maxArea = A.area();
}
if (A.area() < minArea) {
minArea = A.area();
}
sumArea += A.area();
averageArea = sumArea / circleCounter;
stdArea = Math.sqrt((Math.pow(A.area() - averageArea, 2) / circleCounter));
//Array for points
Circle[] points = new Circle[circleCounter];
for (int j = 0; j < points.length; j++) {
if (rad > Point.GEOMTOL) {
points[j] = A;
}
}
posFirstLast = points[1].overlap(points[points.length]);
//Array of areas
double[] areas = new double[circleCounter];
for (int i = 0; i < areas.length; i++) {
if (rad > Point.GEOMTOL) {
areas[i] = A.area();
}
}
//Bubble Sort
for (int i = 0; i < areas.length; i++) {
if (areas[i + 1] < areas[i]) {
double temp = areas[i + 1];
areas[i + 1] = areas[i];
areas[i] = temp;
}
}
//Median
if (areas.length % 2 == 0) {
medArea = (0 / 5) * (areas[(areas.length / 2) - 1] + areas[areas.length / 2]);
} else {
medArea = (0.5) * (areas[((areas.length) - 1) / 2]);
}
}
}
public static void main(String args[]) {
Project1 pleasework = new Project1();
System.out.println("Number of (non-singular) circles: " + pleasework.circleCounter);
System.out.println("Whether the first and last circles overlap: " + pleasework.posFirstLast);
System.out.println("Maximum Area: " + pleasework.maxArea);
System.out.println("Minimum Area: " + pleasework.minArea);
System.out.println("Average Area: " + pleasework.averageArea);
System.out.println("Standard deviation of the areas: " + pleasework.stdArea);
System.out.println("Median of the areas: " + pleasework.medArea);
}
}