subject

Your original program calculated the amount of paint needed, but depending on the width and height, that value could be a long decimal. Your program will better suit the needs of the user if it can calculate the number of cans needed as an integer value. For example, given that 1 gallon = 1 can of paint, we might expect the Paint program from Module Six to output:
Paint needed: 2.142857142857143 gallons
Cans needed: 3.0 can(s)

You might at first think that you could just cast the gallonsPaintNeeded variable from a double to an integer type. However, that would merely cut off the decimal portion of the value, resulting in an underestimate of the number of cans needed. You might also consider rounding the number, but that would not work for the sample output provided above since normal rounding rules would suggest 2.0 cans, an underestimate. So, the computational problem you are faced with is to calculate the number of cans and round up to the nearest whole number. In order to determine if that method for rounding up exists as part of one of Java’s core classes, we need to consult the documentation. There might be a single method that we can use or we might have to use more than one method.

package Paint1;

import java. util. Scanner;
import java. lang. Math;

public class PaintEstimator {

public static void main(String[]args) {
Scanner sc = new Scanner(System. in);
double wallHeight = 0;
double wallWidth = 0.0;
double wallArea = 0;
double gallonsPaintNeeded = 0;
int cansNeeded = 0;

final double squareFeetPerGallon = 350.0;
final double gallonsPerCan = 1.0;

do{
System. out. println("Enter wall height (feet): ");
wallHeight = sc. nextDouble();
}
while(wallHeight <= 0 );

do {
System. out. println("Enter wall width (feet): ");
wallWidth = sc. nextDouble();
}
while((wallWidth <= 0));
wallArea = wallHeight * wallWidth;
System. out. println("Wall area: " + wallArea + "square feet");

gallonsPaintNeeded = wallArea/squareFeetPerGallon;
System. out. println("Paint needed: " + gallonsPaintNeeded + " gallon(s)");

cansNeeded = (int)(Math. ceil(gallonsPaintNeeded)/Math. ceil(gallonsPerCan));

System. out. println("Cans needed: " + (cansNeeded) + " can(s)");
return;
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 20:00
Amanda needs to create an informative print brochure for her local library’s fundraiser dinner. what critical detail must she have before she starts designing the brochure?
Answers: 1
question
Computers and Technology, 23.06.2019 01:50
Create a class named majors that includes an enumeration for the six majors offered by a college as follows: acc, chem, cis, eng, his, phys. display the enumeration values for the user, then prompt the user to enter a major. display the college division in which the major falls. acc and cis are in the business division, chem and phys are in the science division, and eng and his are in the humanities division. save the file as majors.java.
Answers: 2
question
Computers and Technology, 23.06.2019 03:10
Fill in the following program so that it will correctly calculate the price of the orange juice the user is buying based on the buy one get one sale.#include //main functionint main() { int cartons; float price, total; //prompt user for input information printf("what is the cost of one container of oj in dollars? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & price); printf("how many containers are you buying? \n"); scanf(" [ select ] ["%d", "%c", "%f", "%lf"] ", & cartons); if ( [ select ] ["cartons / 2", "cartons % 1", "cartons % 2", "cartons % price", "cartons / price", "cartons / total"] [ select ] ["=", "==", "! =", "< =", "> =", "< "] 0) total = [ select ] ["price * cartons", "cartons * price / 2 + price", "(cartons / 2) * price", "cartons / (2.0 * price)", "(cartons / 2.0) * price + price", "((cartons / 2) * price) + price"] ; else total = ((cartons / 2) * price) + price; printf("the total cost is $%.2f.\n", total); return 0; }
Answers: 2
question
Computers and Technology, 23.06.2019 07:30
What key should you press and hold to select and open multiple files at one time? enter alt control esc
Answers: 1
You know the right answer?
Your original program calculated the amount of paint needed, but depending on the width and height,...
Questions
question
Mathematics, 17.10.2020 22:01
question
Mathematics, 17.10.2020 22:01
question
Chemistry, 17.10.2020 22:01
question
Mathematics, 17.10.2020 22:01
Questions on the website: 13722362