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 01:30
Imagine that you have a friend who is starting a small business and is interested in using social media to spread the word. he is not certain that it is a good move, and has come to you for . would you advise him to use social media to advertise his business? why or why not? support you answer with information from the text.
Answers: 1
question
Computers and Technology, 23.06.2019 00:30
If joey was single and his taxable income was $9,500, how much would he pay in taxes each year?
Answers: 1
question
Computers and Technology, 23.06.2019 04:00
Laire writes a letter to her grandmother, in which she describes an amusement park she visited last week. she adds pictures of that place in her letter. which feature of a word processing program will claire to remove unwanted parts of the pictures?
Answers: 3
question
Computers and Technology, 23.06.2019 09:00
Which best describes the role or restriction enzymes in the analysis of edna a. to break dna into fragments that vary in size so they can be sorted and analyzed b. to amplify small amounts of dna and generate large amounts of dna for analysis c. to purify samples of dna obtained from the environment so they can be analyzed d. to sort different sizes of dna fragments into a banding pattern that can be analyzed
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, 05.03.2021 20:00
question
Mathematics, 05.03.2021 20:00
question
Health, 05.03.2021 20:00
question
Mathematics, 05.03.2021 20:00
Questions on the website: 13722367