Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. For the second part of the Lab, improve the following Java program with functions. You should look for places in the code where similar

image text in transcribed

2. For the second part of the Lab, improve the following Java program with functions. You should look for places in the code where similar statements are repeated and think about how to write function(s) to replace those statements. Unlike the first part of the Lab, in this exercise you will probably want to create one or more functions that return a value, and use the returned values in the rest of the program. This is the Painting.java source file for you to modify (blue lines are my additions): public class Painting public static void main(String[] args) double width, length, wallArea, ceilingArea; final double HEIGHT = 8; System.out.println("Calculation of Paint Requirements"); System.out.print("Enter room length: "); length = Keyboard.nextDouble(); // these 2 lines make a nice function, promptDouble that // takes a string parameter and returns an int; create // that, then replace those 2 lines with this single line: // length = promptDouble("Enter room length: "); System.out.print("Enter room width: "); width = Keyboard.nextDouble(); // these 2 lines should be replaced in the same way: // width = promptDouble("Enter room width: "); wallArea = 2 * (length + width) * HEIGHT; // ignore doors // this line should use a perimeter function instead, as in: // wallArea = perimeter(length, width) * HEIGHT; ceilingArea = length * width; // this line should use a new function called area, // similar to perimeter, like so: // ceilingArea = area (length, width); System.out.println("The wall area is " + wallArea + " square feet."); System.out.println("The ceiling area is " + ceilingArea + " square feet.")

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

Students also viewed these Databases questions