- #1
furboll
- 2
- 0
Hello everyone,
I am new to the forum. Programing was never an interest of mine but it’s an unfortunate requirement for classes I am taking I could really some help. I have tried fixing the code the best I can, but when I run this through Netbeans, no matter what numbers I put in for Wall height and Wall width, I still get an answer of 0. I have no idea what I am missing and I’ve read the (unhelpful) textbook over again. Is there anyone who sees what I am doing wrong and could explain to me ?
I am new to the forum. Programing was never an interest of mine but it’s an unfortunate requirement for classes I am taking I could really some help. I have tried fixing the code the best I can, but when I run this through Netbeans, no matter what numbers I put in for Wall height and Wall width, I still get an answer of 0. I have no idea what I am missing and I’ve read the (unhelpful) textbook over again. Is there anyone who sees what I am doing wrong and could explain to me ?
Code:
package paintestimator;
import java.util.Scanner;
import java.lang.Math;
public 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;
int cansNeeded = 0;
final double squareFeetPerGallons =350 ;
final double gallonsPerCan = 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): ");
wallHeight = scnr.nextDouble();
// Calculate and output wall area
wallArea = wallHeight * wallWidth;
System.out.println("Wall area: square feet "); // A space was needed in between square feet and "
// Calculate and output the amount of paint in gallons needed to paint the wall
gallonsPaintNeeded = wallArea / squareFeetPerGallons; // "/" A space should have beenmbetween wallArea and "/" and squareFeetPerGallons
System.out.println("Paint needed: " + gallonsPaintNeeded + " gallons"); // gallonspaintneeded needed to be corrected to gallonsPaintNeeded
// Calculate and output the number of 1 gallon cans needed to paint the wall, rounded up to nearest integer
cansNeeded = (int) (gallonsPaintNeeded / gallonsPerCan); (needed to add "(int)" and () added around equation
System.out.println("Cans needed: " + cansNeeded + " can(s)");
return;
}