Here is the solution to the above question. The explanation is done in the code itself in the form of comments (see image) for better line by line explanation and better understanding.
Code:
import
java.util.Scanner;
public class PaintCalculator{
// main class
public static void main (String args[]){
int
length,width,height;
// variable decleration for length, width and
height.
double area,gallon;
// variable for area and gallon
System.out.print("\nEnter the
length of the room: ");
// user
input
Scanner s = new Scanner(System.in);
length =
s.nextInt();
System.out.print("\nEnter the width
of the room: ");
// user input
Scanner s2 = new
Scanner(System.in);
width =
s2.nextInt();
System.out.print("\nEnter the
height of the room: ");
// user
input
Scanner s3 = new
Scanner(System.in);
height =
s3.nextInt();
area=computeArea(length,width,height);
// calling computeArea
function and storing the return value in area.
gallon=computeGallons(area);
// calling
computeGallons function and storing the return value in
gallon.
double total_cost=gallon*32;
// calculating total
cose
System.out.println("\nYou will need
"+String.format("%.2f", gallon)+" gallons."); //
showing the gallons
System.out.println("\nTotal cost
will be "+String.format("%.2f", total_cost)+"."); // showing the
total cost.
}
public static double computeArea(double length,double
width,double height){
// function computeArea decleration
return
(length*height*2+height*width*2);
}
public static double computeGallons(double area){
// function computeGallons decleration
return (area/350);
}
}
Output:
How to Run program:
javac PaintCalculator.java
then
java PaintCalculator
done.
Note: If you are still unable to understand, then comment with it and I will be happy to help.
CENGAGE MINDTAP gramming Exercise 3-8 PaintCalculator.java Instructions Assume that a gallon of paint covers about 350...
This exercise requires designing a program which solves the problem described in the problem statement below. Provide comments as necessary in your pseudo-code and the Java program. Your solution must include these components: Flowchart Pseudo-code Hierarchy Chart Program Coded Program Output Problem Statement A painting company has determined that to paint 115 square feet of wall space, the task will require one gallon of paint and 8 hours of labor. The company charges $20.00 per hour for labor. Design a...
This exercise guides you through the process of converting an Area and Perimeter application from a procedural application to an object-oriented application. Create and use an object 1. Open the project named ch04_ex2_Area and Perimeter that’s stored in the ex_starts folder. Then, review the code for the Main class. 2. Create a class named Rectangle and store it in the murach.rectangle package. 3. In the Rectangle class, add instance variables for length and width. The, code the get and set...
AllPaint is a shop that specialises in household paint products. They have approached you, an application developer for your services. They want you to develop an application that they will use in their shop to estimate the amount of paint that customers would need to purchase when they supply dimensions of their houses. Furthermore, they want you to integrate this system with their point of sale system, which would enable them to process paint sales. To process a sale, the...
This code is in java. Create a Java class that has the private double data of length, width, and price. Create the gets and sets methods for the variables. Create a No-Arg constructor and a constructor that accepts all three values. At the end of the class add a main method that accepts variables from the user as input to represent the length and width of a room in feet and the price of carpeting per square foot in dollars...
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...
Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method. Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables...
****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...
Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...
I am required to use the try - catch block to validate the input as the test data uses a word "Thirty" and not numbers. The program needs to validate that input, throw an exception and then display the error message. If I don't use the try - catch method I end up with program crashing. My issue is that I can't get the try - catch portion to work. Can you please help? I have attached what I have...
Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...