Java Reference
In-Depth Information
sellingPrice = (originalPrice + originalPrice
0.80)
0.90
The algorithm is as follows:
a. Get
originalPrice
b. Calculate the
sellingPrice
using the formula:
sellingPrice = (originalPrice + originalPrice
0.80)
0.90
The information needed to calculate the selling price is the original price and the
marked-up percentage.
17.
Suppose that
numOfPages
denotes the number of pages to be faxed and
billingAmount
denotes the total charges for the pages faxed. To calculate the
total charges, you need to know the number of pages faxed.
If
numOfPages
is less than or equal to 10, the billing amount is service charges
plus (
numOfPages
0.20)
; otherwise, billing amount is service charges plus
10
0.20
plus (
numOfPages - 10
)
0.10
.
You can now write the algorithm as follows:
a. Get
numOfPages
.
b. Calculate billing amount using the formula:
if (numOfPages is less than or equal to 10)
billingAmount = 3.00 + (numOfPages
0.20);
otherwise
billingAmount = 3.00 + 10
0.20 + (numOfPages - 10)
0.10;
Chapter 2
1. a. False; b. False; c. False; d. False; e. True; f. True; g. True; h. False; i. True; j. False
3. a
5. The identifiers
firstName
and
FirstName
are not the same. Java is case sensitive.
The first character of
firstName
is lowercase
f
while the first character of
FirstName
is uppercase
F
. So these identifiers are different.
7. a.
3
;b
0.5
;c.
4.5
;d.
38.5
;e.
1
; .
2
;g.
2
;h.
420.0
9.
7
11.
a and c are valid
13.
a.
32 * a + b
b.
'8'
c.
"Julie Nelson"
d.
(b * b - 4 * a * c) / (2 * a)
e.
(a + b) / c * (e * f) - g * h
f.
(-b + (b * b - 4 * a * c)) / (2 * a)
Search WWH ::
Custom Search