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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 01:00, keasiabradley
Search the web for two examples of digital art that you like. the examples must be from different mediums (example: one digital photo and one computer animation not two computer animations). compose an essay for each example you choose about why the piece appeals to you, and identify the medium used.
Answers: 1
image
Computers and Technology, 22.06.2019 02:00, ahmedislife
Alocal reaction will occur at the site of the exposure such as irritation or damage to the skin eye or local reaction will occur at the site of the exposure such as irritation or damage to the skin ireland lounges
Answers: 3
image
Computers and Technology, 23.06.2019 00:00, brooklyn4932
What engine component is shown in the above figure?
Answers: 1
image
Computers and Technology, 23.06.2019 21:20, nathanfletcher
In microsoft word, when you highlight existing text you want to replace, you're in              a.  advanced mode.    b.  automatic mode.    c.  basic mode.    d.  typeover mode
Answers: 1
You know the right answer?
Your original program calculated the amount of paint needed, but depending on the width and height,...

Questions in other subjects: