Results 1 to 4 of 4
  1. #1
    Iam_Sam is offline Member
    Join Date
    Nov 2013
    Location
    USA
    Posts
    4
    Rep Power
    0

    Default 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
    System.out.println("Please enter the room's width:");
    width = input.nextInt();
    
    // prompt user for the room's length
    System.out.println("Please enter the room's length:");
    length = input.nextInt();
    
    // prompt user for the room's height
    System.out.println("Please enter 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
    I appreciate your help guys
    Thank you

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,507
    Rep Power
    5

    Default 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
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Iam_Sam is offline Member
    Join Date
    Nov 2013
    Location
    USA
    Posts
    4
    Rep Power
    0

    Default 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. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,507
    Rep Power
    5

    Default 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
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 3
    Last Post: 10-27-2013, 06:57 PM
  2. Replies: 2
    Last Post: 10-25-2011, 10:26 PM
  3. Textfield not displaying correct text
    By nksjolinder1 in forum AWT / Swing
    Replies: 6
    Last Post: 10-25-2011, 09:33 PM
  4. frame not displaying correct contents
    By yemista in forum AWT / Swing
    Replies: 5
    Last Post: 10-20-2011, 05:30 PM
  5. problem with displaying result..
    By SCS17 in forum New To Java
    Replies: 4
    Last Post: 04-23-2008, 11:19 AM

Posting Permissions

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