# Thread: Problem of displaying correct result

1. Member
Join Date
Nov 2013
Location
USA
Posts
4
Rep Power
0

## Problem of displaying correct result

hey guys i need some help please!

i have some problem on the program that i'm working on called "Painters"

I want to display the following results:

Number of gallons required
Total cost of the paint
Total time needed to paint the room
Total labor cost

but my calculation keeps displaying 0 (zeros) :
here is the code:

Java Code:
```
import java.util.Scanner;

public class Painters {

static float DOOR_SIZE;
static float WINDOW_SIZE;
static float SQ_FT_PER_GALLON = 150.0f;

//static float netsquarefeet;
static float grosssquarefeet;
static double PaintPrice;
static double LaborPrice;
static double netsquarefeet;

private static double LaborHours;
private static double PaintCost;
private static double LaborCost;
private static double TotalCost;

// declare all variables to be used

public static void main(String[] args) {

//double Gallons = 0.00;
double LaborHours = 0;
double PaintCost = 0.00;
double LaborCost = 0.00;
double TotalCost = 0.00;

int height,length,width, doors, windows;
int gallons;

// give welcome and instructions to user
System.out.println("Welcome to the painters Helper Program");

Scanner input = new Scanner (System.in);

// prompt user for the room's width
width = input.nextInt();

// prompt user for the room's length
length = input.nextInt();

// prompt user for the room's height
height = input.nextInt();

// prompt user for the number of doors
System.out.println("Please enter the number of doors:");
doors = input.nextInt();

// prompt user for the number of large windows
System.out.println("Please enter the number of windows:");
windows = input.nextInt();

System.out.println("What is the price of the paint per gallon?");
PaintPrice = input.nextDouble();

System.out.println("What is the labor hour cost?");
LaborCost = input.nextDouble();

gallons = computeGallons(length, height, doors, width, windows);

// System.out.println ();
System.out.println("Number of Gallons Required: " + gallons);
System.out.println("Total Time Need To Paint The Room: " + LaborHours);
System.out.println("Total cost of The Paint: \$ " + PaintCost);
System.out.println("Total Labor Cost: \$ " + LaborCost);
System.out.println("Total Cost of The Paint Job: \$ " + TotalCost);

System.out.println("You will need about " + gallons + " "+"gallons of paint for your room.");

} // end of method main

static int computeGallons(int length, int height, int doors, int width, int Windows) {

float grosssquarefeet, subtraction,netsquarefeet;

int gallons;

// gross square feet = height * 2 * (length + width)
grosssquarefeet = height * 2 * ( length + width);

// net square feet = gross square feet - subtractions
subtraction = (doors * DOOR_SIZE) + (Windows * WINDOW_SIZE);

gallons = (int) (netsquarefeet / 150.0);    //HERE IT SHOWS A REDLINE UNDER NETSQUAREFEET: VARIABLE NETSQUAREFEET MIGHT NOT HAVE INITIALIZED
LaborHours = (netsquarefeet * 8) / 150.00;
PaintCost = (netsquarefeet * PaintPrice) / 150.00;
LaborCost = LaborHours * 15;
TotalCost = LaborCost + PaintCost;

netsquarefeet = grosssquarefeet - subtraction;

// gallons = netSqFt / SQ_FT_PER_GALLON rounded to the nearest gallon
gallons = Math.round(netsquarefeet / SQ_FT_PER_GALLON);
return gallons;

} // end of computegGallons

} // end of class PaintersHelper```
Thank you

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,738
Rep Power
10

## Re: Problem of displaying correct result

You're calculating lots of things. You need to be careful when you mix int values with floating point. First, I suggest you use double over float. Second, you may want to make everything a double to see if you are getting any values. Remember, if the numerator is smaller than the denominator the result will be zero when assigned to an int.

Regards,
Jim

3. Member
Join Date
Nov 2013
Location
USA
Posts
4
Rep Power
0

## Re: Problem of displaying correct result

Hi Jim thank you for answer....well i did what you said (by making everything double) nothing happen still the same problem:

Java Code:
```static double computeGallons(double length, double height, double doors, double width, double Windows) {

double grosssquarefeet, subtraction,netsquarefeet;

double gallons;

// gross square feet = height * 2 * (length + width)
grosssquarefeet = height * 2 * ( length + width);

// net square feet = gross square feet - subtractions
subtraction = (doors * DOOR_SIZE) + (Windows * WINDOW_SIZE);

gallons = (netsquarefeet / 150.0); [B]// RED LINE UNDER netsquarefeet. It says variable might not have been initialized[/B]
LaborHours = (netsquarefeet * 8) / 150.00;
PaintCost = (netsquarefeet * PaintPrice) / 150.00;
LaborCost = LaborHours * 15;
TotalCost = LaborCost + PaintCost;

netsquarefeet = grosssquarefeet - subtraction;

// gallons = netSqFt / SQ_FT_PER_GALLON rounded to the nearest gallon
gallons = Math.round(netsquarefeet / SQ_FT_PER_GALLON);
return gallons;

} // end of computegGallons

} // end of class PaintersHelper```
I'm kinda frustrated i ve been working on this program pretty much all day :(

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,738
Rep Power
10

## Re: Problem of displaying correct result

Okay, you are doing a couple things incorrectly. First, you are redeclaring your variables inside of main. Remove the type declaration. All you want to do is initialize them. Second and most important, you are using netsquarefeet before you compute it. Move the computation above the gallon computation.

Regards,
Jim

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•