这是我用于项目的类文件的当前代码,我在 public double highStoreSales(store) 和 public doubleaverageStoreSales(quarter) 行上收到两个标识符预期错误
我错过了什么?
import java.io.File;
import java.text.DecimalFormat;
import java.util.Scanner;
import java.io.IOException;
import java.util.*;
import javax.swing.*;
import java.awt.*;
public class SalesAnaylzer //extends SalesManager
{
DecimalFormat pricePattern = new DecimalFormat("$#0.00");
int[][] sales = new int[3][4];
public SalesAnaylzer(String fileName) throws IOException {
File inputFile = new File(fileName);
Scanner scan = new Scanner(inputFile);
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 6; col++) {
sales[row][col] = scan.nextInt();
}
}
}
public String toString() {
String data = "";
for (int row = 0; row < 4; row++) {
data = data + "\nStore " + (row + 1) + ": ";
for (int col = 0; col < 6; col++) {
data = data + "QTR " + (col + 1) + ": " + pricePattern.format(sales[row][col]) + " ";
}
}
return data;
}
public double totalSales() {
double total = 0.0;
for (int row = 0; row < 4; row++) {
for (int col = 0; col < 6; col++) {
total = total + sales[row][col];
}
}
return total;
}
public double highStoreSales(store) {
double highest = 0.0;
for (int row = 0; row < 4; row++) {
if (sales[row][store] > highest)
highest = sales[row][store];
}
return pricePattern.format(highest);
}
public double averageStoreSales(quarter) {
double total = 0.0;
double avg = 0.0;
for (int col = 0; col < 6; col++) {
total = total + sales[quarter][col];
}
avg = (total / 4);
return pricePattern.format(avg);
}
}
最佳答案
您的参数名称没有类型,例如:
public double averageStoreSales(quarter)
您需要说明quarter
是什么类型,例如:
public double averageStoreSales(int quarter)
// -----------------------------^
关于java - 类文件错误 : "Identifier expected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21683783/