Created
July 16, 2017 17:25
-
-
Save bharris62/55343faab7bce30f736be23b8363cb86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import java.lang.Math; // Note: Needed for math functions | |
class PaintEstimator { | |
public static void main(String[] args) { | |
Scanner scnr = new Scanner(System.in); | |
double wallHeight = 0.0; | |
double wallWidth = 0.0; | |
double wallArea = 0.0; | |
double gallonsPaintNeeded = 0.0; | |
double cansNeeded = 0; | |
final double SQUARE_FEET_PER_GALLON = 350.0; | |
final double GALLONS_PER_CAN = 1.0; | |
System.out.println("Enter wall height (feet): "); | |
wallHeight = scnr.nextDouble(); | |
// Prompt user to input wall's width | |
System.out.println("Enter wall width (feet): "); | |
wallWidth = scnr.nextDouble(); | |
// Calculate and output wall area | |
wallArea = wallHeight * wallWidth; | |
System.out.println("Wall area: " + wallArea + " square feet"); | |
// Calculate and output the amount of paint in gallons needed to paint the wall | |
gallonsPaintNeeded = wallArea / SQUARE_FEET_PER_GALLON; | |
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons"); | |
// Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer | |
cansNeeded = gallonsPaintNeeded / GALLONS_PER_CAN; //Hint: this line is missing two operations | |
System.out.println("Cans needed: " + Math.round(cansNeeded) + " can(s)"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment