Sale!

# Project: Variables and Expressions

\$35.00

Category:

Project: Variables and Expressions Page 1 of 3
Page 1 of 3
Deliverables
Your project files should be submitted to Web-CAT by the due date and time specified. In order to
avoid a late penalty for the project, you must submit your completed code files to Web-CAT by 11:59
p.m. on the due date. If you are unable to submit via Web-CAT, you should e-mail your project Java
Files to submit to Web-CAT:
• Expression.java
• SquareUnits.java
Specifications
Overview: You will write two programs this week. The first will find the result of a specified
expression after reading input values for x and y, and the second will calculate the integral number of
units (acres, square yards, and square feet) in a specified number of square inches.
• Expression.java
Requirements: A program is needed that inputs values of type double for x and y and solves for
the result of the indicated expression when xy is not equal to zero. If xy is equal to zero, then the
result is zero.
Design: The result should be calculated as follows (except for the special case):
������ = (10� + 32.6) (5� − 1.567)
��
for �� ≠ 0
Note: if xy is 0, then result is undefined.
Three examples of program output for the indicated input values are shown below. Note that
lines 2 and 3 for the input values begin with tab which is equivalent to three spaces in jGRASP
(i.e., your program should use the \t escape sequence for a tab).
Example #1
Line # Program output
1
2
3
4
5
—-jGRASP exec: java Expression
result = (10x + 32.6) (5y – 1.567) / xy
x = 1.5
y = 3.1
result = 142.62597849462367
—-jGRASP: operation complete.
Project: Variables and Expressions Page 2 of 3
Page 2 of 3
Example #2
Line # Program output
1
2
3
4
5
—-jGRASP exec: java Expression
result = (10x + 32.6) (5y – 1.567) / xy
x = 0.0
y = 34.7
result is “undefined”
—-jGRASP: operation complete.
Example #3
Line # Program output
1
2
3
4
5
—-jGRASP exec: java Expression
result = (10x + 32.6) (5y – 1.567) / xy
x = 12.5
y = 0
result is “undefined”
—-jGRASP: operation complete.
Example #4
Line # Program output
1
2
3
4
5
—-jGRASP exec: java Expression
result = (10x + 32.6) (5y – 1.567) / xy
x = -1.5
y = -6.2
result = -61.632172043010755
—-jGRASP: operation complete.
Code: Your numeric variables should be of type double. Use an if-else statement to determine if
the divisor in the expressions is zero. Note that the value of x is zero in Example #2 and that the
value of y is zero in Example #3, which means the divisor, xy, is zero each case and result is
undefined.
Test: You are responsible for testing your program, and it is important to not rely only on the
examples above. Remember that the input values are doubles, so be sure to test both positive and
negative values (with and without a decimal point) for x and y. You should use a calculator or
• SquareUnits.java
Requirements: A surveyor requires a program that allows the user to enter a value in square
inches and then displays the combination of acres, square yards, square feet, and square inches so
that each value is maximized in order by acres, square yards, square feet, and finally square
inches. The input value should not exceed 1,000,000,000 square inches. You can assume the user
will always enter a non-negative value; however, negative values will also work.
Project: Variables and Expressions Page 3 of 3
Page 3 of 3
Design: The surveyor would like the output to look as shown below in the two examples when
1234567890 is entered as the input for one run and 987654321is entered for another run. All
numeric variables should be of type int.
Example #1
Line # Program output
1
2
3
—-jGRASP exec: java SquareUnits
Enter the area in square inches: 1234567890
Limit of 1,000,000,000 square inches exceeded!
—-jGRASP: operation complete.
Example #2
Line # Program output
1
2
3
4
5
6
7
—-jGRASP exec: java SquareUnits
Enter the area in square inches: 987654321
Number of Units:
Acres: 157
Square Yards: 2198
Square Feet: 8
Square Inches: 81
—-jGRASP: operation complete.
Your program must follow the above format with respect to the output. Note that lines 3
through 6 begin with tab (i.e., your output should use the escape sequence for a tab).
Code: In order to receive full credit for this assignment, you must calculate the number of each
unit (acres, square yards, square feet, square inches) and store the value in a variable of type int. It
is recommended as a practice that you do not modify input values once they are stored. Note that
an acre contains 6,272,640 square inches, a square yard contains 1,296 square inches, and a
square foot contains 144 square inches. Your expressions should contain only int variables or int
literals. Commas are not allowed in Java numeric literals (1,296 may be entered as1296 or 1_296)
(6,272,640 may be entered as 6272640 or 6_272_640).
Test: You will be responsible for testing your program, and it is important to not rely only on the
example above. The amount entered can be any valid int value. Project: Variables and Expressions