Sale!

Project: Variables and Expressions

$30.00

Category:
Rate this product

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 in a zip file to your TA before the deadline.
Files to submit to Web-CAT:
• Solver.java
• ImperialDistance.java
Specifications
Overview: You will write two programs this week. One will solve for the result of a specified
formula after reading input values for x, y, and z, and the other will determine the number of miles,
yards, feet, and inches for an input value of a raw distance in inches.
• Solver.java
Requirements: A program is needed that inputs values of type double for x, y, and z and solves
for the result of the indicated formula when z is not equal to zero. If z is equal to zero, then the
result is zero.
Design: The result should be calculated as follows:
������ = (10� + 4.1) (5� + 8.7)

for z ≠ 0
Special case:
������ = 0 for z = 0
Three examples of program output for the indicated input values are shown below. Note that
lines 2 through 4 for the input values begin with tab which is equivalent to three spaces in
jGRASP (i.e., your output should use the escape sequence for a tab).
Example #1
Line # Program output
1
2
3
4
5
6
result = (10x + 4.1) (5y + 8.7) / z
Enter x: 1
Enter y: 1
Enter z: 1
result = 193.17
Project: Variables and Expressions Page 2 of 3
Page 2 of 3
Example #2
Line # Program output
1
2
3
4
5
6
result = (10x + 4.1) (5y + 8.7) / z
Enter x: 4.5
Enter y: 2.0
Enter z: 0.0
result = 0.0
Example #3
Line # Program output
1
2
3
4
5
6
result = (10x + 4.1) (5y + 8.7) / z
Enter x: -10.5
Enter y: -20.7
Enter z: -30.9
result = -309.55728155339807
Code: Your numeric variables should be of type double. Use an if-else statement to determine if
the divisor in the formula is zero. Note that in Example #2, the value of z is zero so the divisor is
zero.
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, y, and z. You should use a calculator or
jGRASP interactions to check your answers.
• ImperialDistance.java
Requirements: A digital laser measure manufacturer would like a program that accepts a raw
distance measurement in inches (of type int) and then displays the distance as a combination of
miles, yards, feet, and inches. When a negative raw distance measurement is entered, an
appropriate message is printed as shown in the first example below.
Design: The digital laser measure manufacturer would like the output to look as shown below
when each of the indicated test values is entered as the raw distance for separate runs of the
program.
Line # Program output
1
2
3
Enter the raw distance measurement in inches: -321
Measurement must be non-negative!
Project: Variables and Expressions Page 3 of 3
Page 3 of 3
Line # Program output
1
2
3
4
5
6
7
8
9
10
Enter the raw distance measurement in inches: 63409
Measurement by combined miles, yards, feet, inches:
miles: 1
yards: 1
feet: 1
inches: 1
63409 in = 1 mi, 1 yd, 1 ft, 1 in
Line # Program output
1
2
3
4
5
6
7
8
9
10
Enter the raw distance measurement in inches: 1234567890
Measurement by combined miles, yards, feet, inches:
miles: 19484
yards: 1712
feet: 1
inches: 6
1234567890 in = 19484 mi, 1712 yd, 1 ft, 6 in
Your program must follow the above format with respect to the output. Note that lines 4
through 7 in two previous examples 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 miles,
yards, feet, and inches and store each of the values in separate variables. Create a Scanner object
on System.in to read in the value for the raw distance using the nextInt() method. It is
recommended as a practice that you do not modify input values once they are read in and stored.
Test: You will be responsible for testing your program, and it is important to not rely only on the
example above. Assume that the amount entered can be any integer less than or equal to
2,147,483,647 (the maximum value for a 32 bit int) and greater than or equal to -2,147,483,648
(the minimum value for a 32 bit int).
Grading
Web-CAT Submission: You must submit both “completed” programs to Web-CAT at the same
time. Prior to submitting, be sure that your programs are working correctly and that have passed
Checkstyle. If you do not submit both programs at once, the submission will receive zero
points for correctness. Activity 1 describes how to create a jGRASP project containing both of
your files.

Scroll to Top