Java Reference
In-Depth Information
f. Write a Java statement(s) that outputs the value of num1 and num2 ,
indicating which is num1 and which is num2 . For example, if num1 is 8
and num2 is 5 , then the output is:
The value of num1 = 8 and the value of num2 = 5.
g. Write a Java statement that multiplies that value of num1 by 2 , adds the
value of num2 to it, and then stores the result in newNum . Then write a
Java statement that outputs the value of newNum .
h. Write a Java statement that updates the value of newNum by adding the
value of the named constant SECRET . Then, write a Java statement that
outputs the value of newNum with an appropriate message.
i. Write Java statements that prompt the user to enter a person's last name
and then store the last name into the variable name .
j. Write Java statements that prompt the user to enter a decimal number
between 0 and 70 and then store the number entered into hoursWorked .
k. Write a Java statement that multiplies that value of the named constant
RATE with the value of hoursWorked and stores the result into the
variable wages .
l. Write Java statements that produce the following output:
Name:
//output the value of the variable name
Pay Rate: $
//output the value of the named constant RATE
Hours Worked:
//output the value of the variable hoursWorked
Salary: $
//output the value of the variable wages
For example, if the value of name is "Rainbow" and hoursWorked is
45.50 , then the output is:
Name: Rainbow
Pay Rate: $12.50
Hours Worked: 45.50
Salary: $568.75
m. Write a Java program that tests each of the Java statements in parts (a)—
(l). Place the statements at the appropriate place in the preceding Java
program segment. Test run your program (twice) on the following input
data:
i. num1 = 13, num2 = 28; name = "Jacobson"; hoursWorked = 48.30 .
ii. num1 = 32, num2 = 15; name = "Cynthia"; hoursWorked = 58.45 .
5. Consider the following Java program in which the statements are in the
incorrect order. Rearrange the statements so that it prompts the user to input
the length and width of a rectangle and output the area and perimeter of the
rectangle.
Search WWH ::




Custom Search