This should be writting in Java language. 1. Start by adding a main() method to
ID: 3567870 • Letter: T
Question
This should be writting in Java language. 1. Start by adding a main() method to your class. We will complete this method shortly, after we write some helper methods to solve the following problem: A painting company has determined that one gallon of paint and eight hours of labor are necessary for every 120 square feet of wall space. You have been asked to write a program that will calculate the time needed, amount of paint needed, and materials cost for a specified job. Note that, for this lab, all of your methods must be "static". 2. First, define a method named gallonsNeeded(). This method takes a double as its argument, representing the total amount of wall space (in square feet) to be covered. The method returns a double corresponding to the number of gallons of paint needed to cover that much wall space. 3. Next, create a method named hoursNeeded(). This method takes a double as its argument, representing the total amount of wall space (in square feet) to be painted. The method returns a double corresponding to the total number of hours required to paint that much wall space. In your method, use (call) the gallonsNeeded() method you defined in the previous step. Remember that 1 gallon of paint corresponds to 8 hours of labor. 4. Third, define a method named paintCost(). This method takes two double arguments, representing the total wall space (in square feet) to be covered, and the cost per gallon of paint. It calculates the total number of gallons of paint needed (just call your method from step (2)) and returns this value times the cost per gallon of paint (as a double). 5. Finally, complete your main() method. main() should do the following: a. Create a Scanner object b. Prompt for and read in the total amount of wall space to be painted c. Prompt for and read in the price per gallon of the paint d. Calculate and print the total number of hours of labor required e. Calculate and print the total number of gallons of paint needed f. Calculate and print the total cost of paint for the job 6. The company charges $18.00 per hour for labor. Add a new method to your program named laborCost(), which takes the total wall space to be covered as an argument and then (via the hoursNeeded() method) calculates the total cost for labor. Then modify main() to display the cost for labor and the total cost for the job (materials plus labor). (+50%)
Explanation / Answer
import java.util.Scanner;
public class Gallon{
public double wallspace1,wallspace2,wallspace3,wallspace4,rate;
public int gallonsNeeded(double wallspace1)
{
return wallspace1/120;
}
public int hoursNeeded(double wallspace2)
{
return (wallspace2/120)*8;
}
public int paintCost(double wallspace3,double rate)
{
double hours=hoursNeeded(wallspace3);
return hours*rate;
}
public int labourCost(double wallspace4){
double totalhours=hoursNeeded(wallspace4);
return tatalhours*18;
}
public static void main(String []args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter wall space");
double wallspace = sc.nextInt();
System.out.println("Enter cost for gallon");
double galloncost = sc.nextInt();
double gallonsneeded=gallonsNeeded(wallspace);
double hoursneeded=hoursNeeded(wallspace);
double labourcost=labourCost(wallspace);
double cost=paintCost(wllspace,galloncost);
System.out.println(gallonsneeded);
System.out.println(hoursneeded);
System.out.println(cost);
System.out.println(labourcost);
double halfpercentile=(labourcost+cost)*0.5;
double overallcost=labourcost+cost+halfpercent;
System.out.println("over all cost for project is",+overallcost);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.