-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