我在調用我的程序主要方法時遇到問題。調用方法時遇到問題
程序的規格如下:
setNoOfVehicles()
:返回擁有車輛的數量。
setWeeklyFuelCost()
:返回所有車輛的平均每週燃氣成本。
calcYearlyFuelCost()
:接收平均每週燃料成本並返回平均年燃料成本。
displayFuelCost()
:接收擁有的車輛數量,平均每週燃料成本和平均年燃料成本。
main()
:
呼叫setWeeklyFuelCost()
並存儲在一個局部變量返回的值。
致電displayFuelCost()
,將其作爲參數發送給setNoOfVehicles()
(每週平均燃料成本的本地變量)以及致電calcYearlyFuelCost()
。
掃描儀是在全球範圍內
public static void main(String[] args)
{
double x = setWeeklyFuelCost();
displayFuelCost(setNoOfVehicles(), x, calcYearlyFuelCost(x)); //This is the correct parameters I needed to pass thru displayFuelCost(). I didn't know this at the time and this is what I was trying to ask in this post.
}
private static int setNoOfVehicles()
{
System.out.print("How many vehicles do I own? ");
int noOfVehicles = input.nextInt();
return noOfVehicles;
}
private static double setWeeklyFuelCost()
{
System.out.print("Enter the average weekly fuel cost for my vehicles: ");
double weeklyFuelCost = input.nextDouble();
return weeklyFuelCost;
}
private static double calcYearlyFuelCost(double weeklyFuelCost)
{
double yearlyFuelCost = 0.0;
yearlyFuelCost = weeklyFuelCost * 52;
return yearlyFuelCost;
}
private static void displayFuelCost(int noOfVehicles, double weeklyFuelCost, double yearlyFuelCost)
{
double difference = yearlyFuelCost - 5044.00;
if(yearlyFuelCost > 5044.00)
{
System.out.printf("No of Vehicles: %d\n"
+ "Avg Weekly Fuel Cost: $%,.2f\n"
+ "Avg Annual Fuel Cost: $%,.2f\n\n"
+ "I am OVER budget by $%,.2f.", noOfVehicles, weeklyFuelCost, yearlyFuelCost, difference);
}
else if(yearlyFuelCost < 5044.00)
{
difference = difference * -1;
System.out.printf("No of Vehicles: %d\n"
+ "Avg Weekly Fuel Cost: $%,.2f\n"
+ "Avg Annual Fuel Cost: $%,.2f\n\n"
+ "I am UNDER budget by $%,.2f. PAARRTY!!! ", noOfVehicles, weeklyFuelCost, yearlyFuelCost, difference);
}
else
{
System.out.printf("No of Vehicles: %d\n"
+ "Avg Weekly Fuel Cost: $%,.2f\n"
+ "Avg Annual Fuel Cost: $%,.2f\n\n"
+ "I am RIGHT ON BUDGET!", noOfVehicles, weeklyFuelCost, yearlyFuelCost, difference);
}
}
}
最後的規範是一個抱着我聲明,呼籲displayFuelCost()
我的問題是,我不知道我需要什麼參數通過displayFuelCost()
。我知道在問這個問題之前我必須使用上面的變量x。
displayFuelCost(setNoOfVehicles(), x, calcYearlyFuelCost(x));
是我需要輸入的所有信息才能正常工作。
具體問題是什麼? – 2012-04-08 21:21:02
問題是什麼? – Bnjmn 2012-04-08 21:22:47
@OliCharlesworth - 他稱它,但它不會來。 – 2012-04-08 21:24:02