Java Reference
In-Depth Information
The first integer
2
is changed to the string
"2"
because it is being combined with
the string
"2 + 2"
. The result is the string
"2 + 2 = 2"
. The last integer
2
is
combined with the string
"2 + 2 = 2"
. So, the last
2
is converted to the string
"2"
. So the final result is
"2 + 2 = 2" + "2"
which is
"2 + 2 = 22"
.
31.
sam.increaseAge(10);
32. The method
toLowerCase
doesn't change the string
test
. To change it, we must
set test equal to the string returned by
toLowerCase
:
test = test.toLowerCase();
33. The two kinds of comments are
//
comments and
/* */
comments. Everything
following a
//
on the same line is a comment. Everything between a
/*
and a
matching
*/
is a comment.
34.
Hello
Student
35. The normal spelling convention is to spell named constants using all uppercase
letters with the underscore symbol used to separate words.
36.
public static final int
ANSWER = 42;
Programming Projects
Visit
www.myprogramminglab.com
to complete select exercises online and get instant
feedback.
1. One way to measure the amount of energy that is expended during exercise is to
use metabolic equivalents (MET). Here are some METS for various activities:
Running 6 MPH:
10 METS
Basketball:
8 METS
Sleeping:
1 MET
The number of calories burned per minute may be estimated using the following
formula:
=
*
*
Weight in kilograms
Write a program that calculates and outputs the total number of calories burned
for a 150-pound person who runs 6 MPH for 30 minutes, plays basketball for
30 minutes, and then sleeps for 6 hours. One kilogram is equal to 2.2 pounds.
2. The video game machines at your local arcade output coupons according to how
well you play the game. You can redeem 10 coupons for a candy bar or 3 coupons
for a gumball. You prefer candy bars to gumballs. Write a program that defines a
Calories
j
Minute
0.0175
MET