我正遇到Java类的这个问题。我想请一些指导。JAVA“calculateFee无法解析为类型”
的问题是:
calculateFee不能被解析为一个类型
AuctionSale.java
public class AuctionSale
public double calculateFee() {
if (takingOffers == true) {
return 0;
} else if (reservePrice > 0) {
return reservePrice/20 + currentOffer/20;
} else {
return currentOffer/10;
}
}
AuctionSaleSystem.java
public class AuctionSaleSystem
private static void displaySalesReport()
{
System.out.println("Current Auction Sales Report:");
System.out.println();
for (int i=0; i<sales.length; i++) {
String itemNumber = sales[i].getItemNumber();
String description = sales[i].getDescription();
Double brokerFee = 0.00;
// Stuck at this point, not able to get past the error
// "calculateFee cannot be resolved to a type" :(
calculateFee brokerFee = new calculateFee();
brokerFee = brokerFee.calculateFee();
System.out.printf("Item Number: %s, Description: %s, Broker fee: %d %n",
itemNumber, description, brokerFee);
}
}
为什么所有的downvotes? –
如果我理解正确'calculateFee()'是类'AuctionSale'的非静态方法。所以为了能够调用它,你必须首先获得这个类的一个实例。所以它应该像这样:'AuctionSale brokerFee = new AuctionSale();双费= brokerFee.calculateFee();' –