Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By Norm

Thread: a couple of issues i need help with

  1. #1
    palagano1989 is offline Member
    Join Date
    Mar 2016
    Posts
    3
    Rep Power
    0

    Default a couple of issues i need help with

    first question is i need to be able to round up "WallPaintGallonsNeeded, DoorsMoldingPaintQuartsNeeded, CeilingPaintGallonNeeded, and FloorMoldingPaintQuartsNeeded) to the nearest whole number. The question here is that i also need it to reflect the price that that goes with each variable. i looked around at different thread and what i saw was just changing the reference and not the actual variable.

    second question when i run the program as soon as it gets to DoorsMoldingColorOrWhite and WindowsMoldingColorOrWhite. it prints out the system.out.print multiple times. why is it doing this and how would i go about fixing it.

    third question i am not getting a result for ActualCeilingSquareFeet

    this is not the finish code i still have a lot a tweaks i need to adjust. i just need a little help fixing her up.
    im sorry if i didnt add comment to code. if its hard to understand i can add comment to let you know what each method is doing.

    Java Code:
    import java.util.Scanner;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    
    public class PaintEstimate
    {
        final static double WallAndCeilingPaintCost = 18.50;//cost for 1 gallon
        final static double WhiteEnamelPaintCost = 9.50;  
        final static double ColorEnamelPaintCost = 12.50;
        final static double CoverageOfWallAndCeilingPaint = 250.00; // coverage of wall and ceiling paint in sqft
        final static double CoverageOfEnamelPaint = 100.00;// coverage of enamel paint both color and whit in linear sqft
        
        private static double IntchesToFeet;
        private static double RoomSquareFeet, CeilingSqaureFeet;
        private static double InchesRoomWidth, InchesRoomLength, InchesRoomHeight, InchesFloorMolding;
        private static double FeetRoomWidth, FeetRoomLength, FeetRoomHeight, FeetFloorMolding;
        private static double NumberOfWindows, NumberOfDoors;
        private static double InchesWindowsHeight, InchesWindowsLength, InchesWindowsMoldingWidth;
        private static double InchesDoorsHeight, InchesDoorsLength, InchesDoorsMoldingWidth;
        private static String WindowsMoldingColorOrWhite, DoorsMoldingColorOrWhite, YesOrNo;
        private static double WindowsMoldingCostPerQuart = 0; // new cost of enamel paint
        private static double DoorsMoldingCostPerQuart = 0; // new cost of enamel paint
        private static double FeetWindowsHeight, FeetWindowsLength, FeetWindowsMoldingWidth;
        private static double FeetDoorsHeight, FeetDoorsLength, FeetDoorsMoldingWidth;
        private static double FirstWallCalculation, WindowsSquareFeet;
        private static double ActualCeilingSquareFeet;
        private static double WindowsMoldingSquareFeet, TotalWindowsMoldingSquareFeet; 
        private static double DoorsMoldingSquareFeet, TotalDoorsMoldingSquareFeet;
        private static double FloorMoldingPreCalculation, TotalFloorMoldingSquareFeet, FloorMoldingSquareFeet;
        private static double CombineOtherSquareFeet, TotalActualWallSquareFeet;
        private static double WallPaintGallonsNeeded, DoorsMoldingPaintQuartsNeeded, WindowsMoldingPaintQuartsNeeded, FloorMoldingPaintQuartsNeeded, CeilingPaintGallonNeed;
        private static double CostOfWallPaint, CostOfDoorsMoldingPaint, CostOfWindowsMoldingPaint, CostOfFloorMoldingPaint, CostOfCeilingPaint, TotalCostOfPaint;
        
        private static NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
        private static DecimalFormat df = new DecimalFormat("#.##");
        
        private static Scanner scan = new Scanner(System.in);
        
        public static void main(String[] args) 
        {
            //do
            //{   
                UserInputWallsAndCeiling();
                UserInputWindows();
                UserInputDoors();
                IntchesToFeet();
                CalculateWallSquareFeet();
                CalculateWindowSquareFeet();
                CalculateActualCeilingSqaureFeet();
                CalculateWindowsMoldingSquareFeet();
                CalculateDoorsMoldingSquareFeet();
                FloorMoldingPreCalculation();
                CalculateFloorMoldingSquareFeet();
                CalculateActualWallSquareFeet();
                CalculatePaintNeeded();
                CalculateCostOfPaint();
                PrintPaint();
                //System.out.print('\f');
                //System.out.print("Do you want to do anther room (y/n)");
                //YesOrNo = scan.nextLine();
                
            //}while(YesOrNo.equals("y"));    
        }
        public static void UserInputWallsAndCeiling()
        {
            System.out.print("What is the room height in inches? ");
            InchesRoomHeight = scan.nextDouble();
            System.out.print("What is the room width in inches? ");
            InchesRoomWidth  = scan.nextDouble();
            System.out.print("What is the room length in inches? ");
            InchesRoomWidth = scan.nextDouble();
            System.out.print("What is the width of the floor molding in inches? ");
            InchesFloorMolding = scan.nextDouble();
        }
        public static void UserInputWindows()
        {
            System.out.print("How many windows are in the room? ");
            NumberOfWindows = scan.nextDouble();
            if(NumberOfWindows > 0)
                {
                    System.out.print("What are the windows height in inches? ");
                    InchesWindowsHeight = scan.nextDouble();
                    System.out.print("What are the windows width in inches? ");
                    InchesWindowsLength = scan.nextDouble();
                    System.out.print("What are the windows molding width in inches? ");
                    InchesWindowsMoldingWidth = scan.nextDouble();
                    System.out.print("Is the windows molding color or white? ");
                    
                    boolean WindowsTrue = false;
                    while (!WindowsTrue)
                        {
                            System.out.print("Is the Window's molding color or white? ");
                            WindowsMoldingColorOrWhite = scan.nextLine();
                            if ( WindowsMoldingColorOrWhite.equals("color"))
                                {
                                    WindowsMoldingCostPerQuart = 12.50; 
                                    WindowsTrue = true;
                                }
                            else if (WindowsMoldingColorOrWhite.equals("white"))
                                {
                                    WindowsMoldingCostPerQuart = 9.50;
                                    WindowsTrue = true;
                                }
                            else
                                {
                                    System.out.print("Please enter if the molding is color or white");
                                }
                        }
                }
        }
        public static void UserInputDoors()
        {
            System.out.print("How many doors are in the room? ");
            NumberOfDoors = scan.nextDouble();
            if(NumberOfDoors > 0)
                {
                    System.out.print("What are the doors height in inches? ");
                    InchesDoorsHeight = scan.nextDouble();
                    System.out.print("What are the doors width in inches? ");
                    InchesDoorsLength = scan.nextDouble();
                    System.out.print("What are the doors molding width in inches? ");
                    InchesDoorsMoldingWidth = scan.nextDouble();
                    
                    boolean DoorsTrue = false; 
                    while (!DoorsTrue)
                        {
                            System.out.print("Is the doors molding color or white? ");
                            DoorsMoldingColorOrWhite = scan.nextLine();
                            if ( DoorsMoldingColorOrWhite.equals("color"))
                                {
                                    DoorsMoldingCostPerQuart = 12.50;
                                    DoorsTrue = true;
                                }
                            else if (DoorsMoldingColorOrWhite.equals("white"))
                                {
                                    DoorsMoldingCostPerQuart = 9.50; 
                                    DoorsTrue = true;
                                }
                            else
                                {
                                    System.out.print("Please enter if the molding is color or white");
                                }
                         }
                }
        }
        public static void IntchesToFeet()
        {
            FeetRoomWidth = InchesRoomWidth / 12;
            FeetRoomLength = InchesRoomLength / 12;
            FeetRoomHeight = InchesRoomHeight / 12;
            FeetFloorMolding = InchesFloorMolding / 12;
            FeetWindowsHeight = InchesWindowsHeight / 12;
            FeetWindowsLength = InchesWindowsLength / 12;
            FeetWindowsMoldingWidth = InchesWindowsMoldingWidth / 12;
            FeetDoorsHeight = InchesDoorsHeight /12;
            FeetDoorsLength = InchesDoorsLength / 12;
            FeetDoorsMoldingWidth = InchesDoorsMoldingWidth / 12;
            
        }
        public static void CalculateWallSquareFeet()
        {
            FirstWallCalculation = 2 * (FeetRoomLength + FeetRoomWidth) * FeetRoomHeight + FeetRoomLength * FeetRoomWidth;
        }
        public static void CalculateWindowSquareFeet()
        {
            WindowsSquareFeet = FeetWindowsHeight * FeetWindowsLength;
        }
        public static void CalculateActualCeilingSqaureFeet()
        {
            ActualCeilingSquareFeet = FeetRoomWidth * FeetRoomLength;
        }
        public static void CalculateWindowsMoldingSquareFeet()
        {
            WindowsMoldingSquareFeet = (FeetWindowsHeight * 2 + FeetWindowsLength * 2) * FeetWindowsMoldingWidth;
            TotalWindowsMoldingSquareFeet = WindowsMoldingSquareFeet * NumberOfWindows;
        }
        public static void CalculateDoorsMoldingSquareFeet()
        {
            DoorsMoldingSquareFeet = (FeetDoorsHeight * 2 + FeetDoorsLength) * FeetDoorsMoldingWidth;
            TotalDoorsMoldingSquareFeet = DoorsMoldingSquareFeet * NumberOfDoors;
        }    
        public static void FloorMoldingPreCalculation()
        {
            FloorMoldingPreCalculation = (FeetDoorsMoldingWidth * 2 + FeetDoorsLength) * NumberOfDoors;
        }
        public static void CalculateFloorMoldingSquareFeet()
        {
            FloorMoldingSquareFeet = (FeetRoomLength * 2 + FeetRoomWidth * 2) - FloorMoldingPreCalculation;
            TotalFloorMoldingSquareFeet = FloorMoldingSquareFeet * FeetFloorMolding;
        }
        public static void CalculateActualWallSquareFeet()
        {
            CombineOtherSquareFeet = TotalFloorMoldingSquareFeet + TotalDoorsMoldingSquareFeet + TotalWindowsMoldingSquareFeet;
            TotalActualWallSquareFeet = FirstWallCalculation - CombineOtherSquareFeet;
        }
        public static void CalculatePaintNeeded()
        {
            WallPaintGallonsNeeded = TotalActualWallSquareFeet / CoverageOfWallAndCeilingPaint;
            DoorsMoldingPaintQuartsNeeded = TotalDoorsMoldingSquareFeet / CoverageOfEnamelPaint;
            WindowsMoldingPaintQuartsNeeded = WindowsSquareFeet / CoverageOfEnamelPaint;
            FloorMoldingPaintQuartsNeeded = TotalFloorMoldingSquareFeet / CoverageOfEnamelPaint;
            CeilingPaintGallonNeed = ActualCeilingSquareFeet / CoverageOfWallAndCeilingPaint;
        }
        public static void CalculateCostOfPaint()
        {
            CostOfWallPaint = WallPaintGallonsNeeded *  WallAndCeilingPaintCost;
            CostOfDoorsMoldingPaint = DoorsMoldingPaintQuartsNeeded * DoorsMoldingCostPerQuart;
            CostOfWindowsMoldingPaint = WindowsMoldingPaintQuartsNeeded * WindowsMoldingCostPerQuart;
            CostOfFloorMoldingPaint = FloorMoldingPaintQuartsNeeded * WhiteEnamelPaintCost;
            CostOfCeilingPaint = CeilingPaintGallonNeed * WallAndCeilingPaintCost;
            TotalCostOfPaint = CostOfWallPaint + CostOfDoorsMoldingPaint + CostOfWindowsMoldingPaint + CostOfFloorMoldingPaint + CostOfCeilingPaint;
        }
        public static void PrintPaint()
        {
            System.out.println("Room wall area: " + df.format(TotalActualWallSquareFeet) + " SQFT");
            System.out.println("Gallons of wall Paint Needed " + WallPaintGallonsNeeded + " Cost of Paint: " + currencyFormatter.format(CostOfWallPaint) );
            System.out.println("Ceiling area: " + df.format(ActualCeilingSquareFeet) + " SQFT");
            System.out.println("Gallons of Ceiling Paint Needed " + CeilingPaintGallonNeed + " Cost of Paint: " + currencyFormatter.format(CostOfCeilingPaint) );
            System.out.println("Door Molding Area: " + df.format(TotalDoorsMoldingSquareFeet) + " Linear SQFT");
            System.out.println("Quarts of Door Molding Paint Needed " + DoorsMoldingPaintQuartsNeeded + " Cost of Paint: " + currencyFormatter.format(CostOfDoorsMoldingPaint));
            System.out.println("Window Molding Area: " + df.format(WindowsSquareFeet) + " Linear SQFT");
            System.out.println("Quarts of Window Molding Paint Needed " + WindowsMoldingPaintQuartsNeeded + " Cost of Paint: " +  currencyFormatter.format(CostOfWindowsMoldingPaint));
            System.out.println("BaseBoard Molding Area: " + df.format(TotalFloorMoldingSquareFeet) + " Linear SQFT");
            System.out.println("Quarts of Ceiling Paint Needed " + FloorMoldingPaintQuartsNeeded + " Cost of Paint: " + currencyFormatter.format(CostOfFloorMoldingPaint));
            System.out.println("Total Paint Cost: " + currencyFormatter.format(TotalCostOfPaint));
            //System.out.println("");
        }
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: a couple of issues i need help with

    Quote Originally Posted by palagano1989 View Post
    first question is i need to be able to round up "WallPaintGallonsNeeded, DoorsMoldingPaintQuartsNeeded, CeilingPaintGallonNeeded, and FloorMoldingPaintQuartsNeeded) to the nearest whole number. The question here is that i also need it to reflect the price that that goes with each variable. i looked around at different thread and what i saw was just changing the reference and not the actual variable.
    What reference are you talking about? Everything is declared as a static primitive so you have no references (except String which doesn't apply here).

    second question when i run the program as soon as it gets to DoorsMoldingColorOrWhite and WindowsMoldingColorOrWhite. it prints out the system.out.print multiple times. why is it doing this and how would i go about fixing it.

    third question i am not getting a result for ActualCeilingSquareFeet
    Use some print statements to print variables during program execution. This helps track down problems in your logic.
    To round a variable, check out the Math class.

    Why are you declaring everything static? Is this a requirement from a course instructor? Have you covered Java classes
    yet?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    palagano1989 is offline Member
    Join Date
    Mar 2016
    Posts
    3
    Rep Power
    0

    Default Re: a couple of issues i need help with

    i used the wrong word in my first question. they just use like ceil or math.round to round up to print out the number. these were some of the requirements

    Program must make full use of methods.
    The main method should only control the main program logic.
    All variables and constants should be private in the class.
    Prompts for user input should be clear and concise.
    The proper math is used for all calculations.
    Screen inputs should be cleared between room requests.
    All screen displays must contain appropriate text.
    Good program documentation.
    Project named and submitted correctly.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: a couple of issues i need help with

    Well, there is nothing there requiring the use of static everywhere. But you have clearly put in a lot of time on this. To help with
    the debugging I recommend that you take all the prompts for room measurements and place them in a separate method (call it getInput()). Then, make another method called something like getDebuggingInput() and simply assign the variables with values sans user prompting. Then you can continue to do the calculations. Using print statements at various places will let you track where the problems is for the ceiling. For debugging, call the getDebuggingInput() method. For regular use, call the getInput() method. This is a common technique that saves a lot of time debugging programs that require user interaction.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: a couple of issues i need help with

    Another technique for making debugging of code that uses the Scanner class's method for getting user input is to change the constructor to preload all the inputs that the user will make in the order that they would be entered. For example:
    Java Code:
        private static Scanner scan = new Scanner("14 33 35 4\n"); //System.in);
    jim829 likes this.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    palagano1989 is offline Member
    Join Date
    Mar 2016
    Posts
    3
    Rep Power
    0

    Default Re: a couple of issues i need help with

    thank you all for your help.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: a couple of issues i need help with

    Quote Originally Posted by palagano1989 View Post
    thank you all for your help.
    You're welcome! And if you continue to have problems with your code, someone will be here to assist.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: a couple of issues i need help with

    BTW, if you decide to use Norm's method of entering debugging input, you should change your scan.nextLine() calls to scan.next(). Otherwise,
    your code will throw an exception.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: a couple of issues i need help with

    second question when i run the program as soon as it gets to DoorsMoldingColorOrWhite and WindowsMoldingColorOrWhite. it prints out the system.out.print multiple times. why is it doing this and how would i go about fixing it.
    Look at lines 87 and 92.

    And you need to go back and look carefully how you assign user input to the variables. I think you will then find your problem.

    Regards,
    Jim
    Last edited by jim829; 05-16-2016 at 05:44 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. A couple GUI questions.
    By SpicyHero in forum New To Java
    Replies: 7
    Last Post: 09-22-2013, 05:30 AM
  2. A couple of questions
    By perfidia in forum Java Applets
    Replies: 0
    Last Post: 06-14-2013, 12:05 PM
  3. Couple questions
    By L2Code in forum New To Java
    Replies: 7
    Last Post: 03-22-2013, 10:54 PM
  4. Couple of Problems
    By joz_12345 in forum Java 2D
    Replies: 2
    Last Post: 03-06-2008, 05:13 PM

Posting Permissions

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