-1
这些是我给我的程序编写的指令: 编写一个程序,计算用于房间的油漆桶数量和最佳购买数量为 。 您需要询问房间的高度以及房间的长度和宽度。房间是长方形的。你必须 油漆墙壁和天花板,但不是地板。没有窗户或天窗。您可以购买以下 大小的油漆桶。 •5升桶每个售价15美元,占地1500平方英尺。 •1升桶的成本为4美元,占地300平方英尺。For循环找出涂漆房间需要多少油漆
我已经写了大部分代码,我只需要帮助计算出使用for循环购买了多少个桶。 这里是我的程序:
public class BrandonLatimerS5L1TryItSolveIt7 {
public static void main(String[] args){
//declares variables
double length;
double width;
double height;
double ceilingArea;
double wallsArea;
//initializes bucket variables
int fiveLiterBucket = 1500;
int oneLiterBucket = 300;
//Prompts user and gets input for length
Scanner input = new Scanner(System.in);
System.out.println("Please enter the length of the room in feet: ");
length = input.nextDouble();
//prompts user and gets input for width
System.out.println("Please enter the width of the room in feet: ");
width = input.nextDouble();
//Prompts for input and gets input for height
System.out.println("And lastly, please enter the height of the room in feet: ");
height = input.nextDouble();
//figures out the total area that needs to be painted
ceilingArea = length * width;
wallsArea = (2 * (width * height) + (2 * (length * height)));
double totalArea = ceilingArea + wallsArea;
//For loop to figure out how much paint will be needed.
for(int numOfBuckets = 0; totalArea > 1; numOfBuckets++){
totalArea = totalArea - (totalArea/1500);
System.out.println("You will need " + numOfBuckets + " buckets.");
continue;
/*
* This program taught me to use the for loop. I just can't seem to figure out how to find the amount of paint I need to buy.
*/
}
}
任何帮助,不胜感激!
这完全是数学。一个for循环不应该是必需的。 – Carcigenicate