我不断收到以下代码的错误提示:
为了参考,在一个单独的文件中,我保存了在类型BigDecimal中,方法add(BigDecimal)不适用于参数(pay)
pay
类,并且也导入了BigDecimal
。请问有哪位可以指出我的不足/误解吗?我已经尝试找到解决方案,但是找不到合适的东西。import java.util.Scanner;
import java.math.BigDecimal;
class SalesPreInt {
public static void main(String[] args) {
Pay pay = new Pay();
pay.basePay();
BigDecimal intCalc = new BigDecimal("0.15");
Scanner userInput = new Scanner(System.in);
System.out.println("What were your total sales?");
BigDecimal salesPre = userInput.nextBigDecimal();
System.out.println("You're Total Sales were "+salesPre);
userInput.close();
BigDecimal postIntCalc = salesPre.multiply(intCalc);
BigDecimal salesCom = postIntCalc.add(salesPre);
int finalCalc = salesCom.add(pay);
System.out.println("Your total sales including commission is "+salesCom);
System.out.println("Your total pay is"+finalCalc);
}
}
以下是 pay.java 文件:
import java.math.BigDecimal;
public class Pay {
public void basePay() {
int basePay = 50000;
BigDecimal bd = new BigDecimal(String.valueOf(basePay));
}
}
pay pay = new pay();
这个写法很容易出问题 - 考虑使用Java的命名规范,即将类名首字母大写。这样就应该写成Pay pay = new Pay();
。 - fvupay
重命名为Pay
,请同时更新SalesPreInt
代码。顺便说一句:您的评论缺少basePay
方法。(针对其他评论:您无法在评论中格式化代码。这就是为什么您应该将其添加到问题中的原因 ;))。 - Tompay.basePay();
。 - fvu