Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use some comments to help me understand! Thanks. Program to calculate the # gallons of paint needed to paint walls of a room one

Please use some comments to help me understand! Thanks.

Program to calculate the # gallons of paint needed to paint walls of a room one color given room's length, width, and height.

Create 2 static class constants in your PaintCalculator (declare under the class heading but before the main method.)

final static int SQUARE_FEET_PER_GALLON = 350; final static float PRICE_PER_GALLON = 32.49f;

Ask the user to input the room length, width, height. Allow the user to enter a decimal number, and store the values as floats.

Create the following 4 STATIC methods that will be called from the main program. Pass any needed values into the methods and return values as needed (or not). Other than the constants above there should be NO class-level instance variables. All variables should be declared locally within method, or as arguments to methods.

  • calculateRoomArea() - This method should calculate the wall surface area of the room and round up the surface area to the nearest whole number.
  • calculateGallonsNeeded() - This method should calculate the number of gallons required to paint the room the same color, and round up to the nearest whole number of gallons of paint needed
  • calculateTotalCost() - This method should calculate the cost to paint the room. Tax and other supplies do not need to be included.
  • printSummary() - This method should print out a summary of the total surface area of the walls of the room, total gallons needed, and cost needed to paint the room. The cost of the room should be formatted to using a $ and to exactly 2 decimal places using the NumberFormat class. See example code below.

Ex:

float cost = 32.49f;

NumberFormat cf = NumberFormat.getCurrencyInstance(); String costFormatted = cf.format(cost);

You need to use Math.ceil() instead of Math.round() because you will always need at least 1 gallon of paint. (i.e. You always need to go up to the next integer - if # gallons needed is 4.2 - you still need 5 gallons of paint). Math.ceil() takes doubles as parameters and returns a double - so you must type cast your variables passed into ceil to doubles, and the result to an int.

Ex:

float a = 2.1f;

float b = 1.1f; int sumUp = (int)Math.ceil( (double) (a + b));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions

Question

e. What difficulties did they encounter?

Answered: 1 week ago