我试图找到股票的购买价格。我不能乘以stocksBought
and stockPrice
。
getStocksBought方法返回购买的股票数量
getStockBoughtPrice方法在购买时返回一只股票的价格
getBuyingPrice方法通过将 getStocksBought 返回的值与 getStockBoughtPrice 返回的值相乘来返回购买价格
代码
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 –
您的两种方法都需要一个Scanner
参数(并且您没有传递一个)。就像是,
public static double getBuyingPrice(){
Scanner kb = new Scanner(System.in);
double buyingPrice = getStocksBought(kb) * getStockBoughtPrice(kb);
return buyingPrice;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句