Problem

Understanding Sequential Statements In this exercise, you use what you have learned ab...

Understanding Sequential Statements

In this exercise, you use what you have learned about sequential statements to read a scenario and then answer Questions 1-4.

Suppose you have written a Java program that calculates the amount of paint you need to t" cover the walls in your family room. Two walls are 9 feet high and 19.5 feet wide. The other two walls are 9 feet high and 20.0 feet wide. The salesperson at the home improvement store told you to buy 1 gallon of paint for every 150 square feet of wall you need to paint. Suppose you wrote the following code, but your program is not compiling. This program is saved in a file named Paint.java and is included in the student files for this chapter. Take a few minutes to study this code, and then answer Questions 1-4.

1. The first error you receive from the javac compiler is as follows:

Paint.java:8: error: possible loss of precision

int width1= 19.5;

required: int

found :double

What do you have to do to fix this problem? __________________________________________

2. The second error you receive from the javac compiler is this: numGal

Paint.java:12: error: possible loss of precision squareFeet / 150;

1 ons required: int

found :double

What must you do to fix this problem? __________________________________________

3. Even if you fix the problems identified in Question 1 and Question 2, you still have a problem with this program. It has to do with the order in which your statements are written. Identify the problem, and then determine what you need to do to fix the problem. On the following lines, describe how to fix the problem. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________

4. You have two variables declared in this program to represent the height of your walls, hei ghtl and height2. Do you need both of these variables? If not, how would you change the program? Be sure to identify all of the changes you would make. _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________ _____________________________________________________________________________________

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT