Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use Methods to create Paint Job Estimator

843789Oct 9 2009 — edited Oct 9 2009
Problem:

A painting company has determined that for every 115 square feet of wall space, one gallon of paint and eight hours of labor will be required. The company charges $18.00 per hour for labor. Write a program that allows the user to enter the number of rooms to be painted and the price of the paint per gallon. It should also ask for the square feet of wall space in each room. The program should have methods* that return the following data:
- The number of gallons of paint required
- The hours of labor required
- The cost of the paint
- The labor charges
- The total cost of the paint job
Then it should display the data on the screen.

This is what I have so far. I tried, but I do not know how should I do for methods. Please help me! Thank you.
import java.util.Scanner;
import java.text.DecimalFormat;

public class PaintJobEstimator
{
	public static void main(String[] args)
	{
		int sizeOfWall = 115; 			// Size of wall in 
										// each room is 115 ft^2.
		int gallon = 1;					// 1 gallon to paint 
										// per 115 ft^2.
		int hoursOfLabor = 8; 			// 8 hours to paint per 
										// 115 ft^2.
		int laborCostPerHour = 18; 		// Labour cost per hour
										// in each room
		
		// Create Scanner object for kb input.
		Scanner kb = new Scanner(System.in);
		
		// Create a DecimalFormat object.
		DecimalFormat formatter = new DecimalFormat("#0.00");
		
		//------------------
		// Questions to ask
		//------------------
		// Get the # of ft^2 of wall space in each room.
		System.out.print("Enter the number of wall space in " +
						"each room (in square feet): ");
		double sizeToPaint = kb.nextDouble();
		
		// Get the # of rooms to be painted.
		System.out.print("Enter the number of rooms " +
						"to be painted: ");
		double numberOfRooms = kb.nextDouble();
		
		// Get the price of the paint per gallon.
		System.out.print("Enter the price of the paint " +
						"per gallon: ");
		double priceOfPaint = kb.nextDouble();
		
		// Calculate how many of 115 ft^2 block is there.
		double roomCostUnit 
			= (sizeToPaint * numberOfRooms)/sizeOfWall;
		
		//-------------
		// Call method.
		//-------------
		
                // I think I have to have Methods here... but I do not know.
		
		//-------------
		// Calculation
		//-------------
		//1. Calculate the # of gallons of paint required.
		double numberOfGallons = gallon * roomCostUnit;
		
		//2. Calculate the hours of labor required.
		double hoursRequired = hoursOfLabor * roomCostUnit;
		
		//3. Calculate the cost of the paint.
		double paintCostTotal = numberOfGallons * priceOfPaint;
		
		//4. The labor charges.
		double laborCostTotal = hoursRequired * laborCostPerHour;
		
		//5. The total cost of the paint job.
		double jobCostTotal = paintCostTotal + laborCostTotal;
		
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 6 2009
Added on Oct 9 2009
4 comments
1,683 views