Computers and Technology

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;
}
}

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 16:50, Tyrant4life
Consider a slotted aloha system, where the time slot equals the fixed duration of each packet. assume that there are 4 stations a, b,c, d sharing the medium. (a) stations a, b,c, d receive one packet each from higher layers at times 1.3, 1.5, 2.6,5.7 respectively. show which transmissions take place when, according to the slottedaloha protocol; describe all transmissions until all four packets have been successful. when needed, each station has access to the following sequence of random number, provided by a random number generator and drawn uniformly between 0 and 1: (1) station a draws numbers: 0.31, 0.27, 0.78, 0.9, 0.9, 0.11, 0. (2) station b draws numbers: 0.45, 0.28, 0.11, 0.83, 0.37, 0.22, 0. (3)station c draws numbers: 0.1, 0.2, 0.3, 0.4, 0. (4) station d draws numbers: 0.36, 0.77, 0.9, 0.1, 0.1, 0.1, 0.1, 0. (b) in slotted aloha, a station transmits in each time slot with a given probability. what probabilities would you assign to each of the four stations so as to: (i) maximize the efficiency of the protocol? (ii) maximize fairness among the four stations? (c) will the efficiency increase or decrease if we modify slotted aloha as follows: (i) get rid of slots and allow stations to transmit immediately? (ii) implement carrier sensing? (iii) implement collision detection? (iv) implement collision avoidance?
Answers: 3
image
Computers and Technology, 23.06.2019 01:00, EhHannuh6865
Let r be a robotic arm with a fixed base and seven links. the last joint of r is a prismatic joint, the other ones are revolute joints. give a set of parameters that determines a placement of r. what is the dimension of the configuration space resulting from your choice of parameters?
Answers: 3
image
Computers and Technology, 23.06.2019 12:30, legend101xD
Animations and transitions are added from the
Answers: 1
image
Computers and Technology, 23.06.2019 14:30, ahmedeldyame
Select the correct answer. which step can possibly increase the severity of an incident? a. separating sensitive data from non-sensitive data b. immediately spreading the news about the incident response plan c. installing new hard disks d. increasing access controls
Answers: 2
Do you know the correct answer?
Your original program calculated the amount of paint needed, but depending on the width and height,...

Questions in other subjects:

Konu
Mathematics, 30.03.2021 04:50