【发布时间】:2019-09-18 13:15:18
【问题描述】:
一家油漆公司已确定,每 115 平方英尺的墙壁空间,一加仑 将需要油漆和八小时的劳动。公司每小时收费 18.00 美元 为劳动。编写一个程序,允许用户输入要绘制的房间数量 以及每加仑油漆的价格。它还应该要求墙壁空间的平方英尺 每个房间。该程序应具有返回以下数据的方法: • 所需油漆的加仑数 • 所需的工时 • 油漆的成本 • 人工费 • 油漆工作的总成本 然后它应该在屏幕上显示数据。
我还没有解决这个问题的人工部分,但由于paintNeeded 变量,我无法打印costOfPaint()。
我已经尝试将 costOfPaint 方法中的语句写入 main 方法,它可以工作。但这无济于事,因为我需要这样做的方法。我知道我的问题与paintNeeded 变量有关,我只是不确定如何解决这个问题。
公共类主{
public static double paintRequired(double totalSquareFeet){
double paintNeeded = totalSquareFeet / 115;
return paintNeeded;
}
public static double costOfPaint(double paintNeeded, double costOfPaint){
double paintCost = paintNeeded * costOfPaint;
return paintCost;
}
public static void main(String[] args){
double costOfPaint = 0;
int totalSquareFeet = 0;
double paintNeeded = 0;
Scanner getUserInput = new Scanner(System.in);
System.out.println("what is the cost of the paint per gallon");
costOfPaint = getUserInput.nextDouble();
System.out.println("How many rooms do you need painted");
int rooms = getUserInput.nextInt();
for(int i = 1; i <= rooms; i++){
System.out.println("how many square feet are in room:" + i);
int roomSquareFeet = getUserInput.nextInt();
totalSquareFeet = roomSquareFeet + totalSquareFeet;
}
System.out.println("the amount of paint needed:" + paintRequired(totalSquareFeet) + "gallons");
System.out.println("the cost of the paint will be: " + costOfPaint(paintNeeded, costOfPaint));
}
}
对于我的 costOfPaint,我一直得到 0。
【问题讨论】: