我试图找到股票的买入价。我无法乘以stocksBought
和stockPrice
。
getStocksBought 方法返回已购买的股票数量
getStockBoughtPrice 方法在购买时返回一只股票的价格
getBuyingPrice 方法通过将getStocksBought返回的值乘以getStockBoughtPrice返回的值
Java代码
public static int getStocksBought(Scanner kb){
System.out.print("Enter the number of stocks bought:");
int stocksBought = kb.nextInt();
return stocksBought;
}
public static double getStockBoughtPrice(Scanner kb){
System.out.print("Enter the price of one stock when bought: ");
double stockBoughtPrice = kb.nextDouble();
return stockBoughtPrice;
}
public static double getBuyingPrice(){
double buyingPrice = getStocksBought() * getStockBoughtPrice();
return buyingPrice;
}
但是我得到了
Method: getStocksBought required:
java.util.Scanner found: no arguments
reason: actual and formal argument lists differ in length –
答案 0 :(得分:4)
您的两种方法都需要Scanner
参数(并且您没有传递一个参数)。像,
public static double getBuyingPrice(){
Scanner kb = new Scanner(System.in);
double buyingPrice = getStocksBought(kb) * getStockBoughtPrice(kb);
return buyingPrice;
}