Java Reference
In-Depth Information
Enter the initial deposit amount: 10000
Enter annual percentage yield: 5.75
Enter maturity period (number of months): 18
Month CD Value
1 10047.92
2 10096.06
...
17 10846.57
18 10898.54
**5.32
( Game: lottery ) Revise Listing 3.8, Lottery.java, to generate a lottery of a two-
digit number. The two digits in the number are distinct. ( Hint : Generate the first
digit. Use a loop to continuously generate the second digit until it is different
from the first digit.)
**5.33
( Perfect number ) A positive integer is called a perfect number if it is equal to
the sum of all of its positive divisors, excluding itself. For example, 6 is the first
perfect number because 6 = 3 + 2 + 1 . The next is 28 = 14 + 7 + 4 + 2
+ 1 . There are four perfect numbers less than 10,000. Write a program to find all
these four numbers.
***5.34
( Game: scissor, rock, paper ) Programming Exercise  3.17 gives a program that
plays the scissor-rock-paper game. Revise the program to let the user continu-
ously play until either the user or the computer wins more than two times than its
opponent.
*5.35
( Summation ) Write a program to compute the following summation.
1
1
1
1
2 +
3 +
4 + c +
1
+ 2
2
2
+ 2
2
3
+ 2
2
624
+ 2
625
**5.36
( Business application: checking ISBN ) Use loops to simplify Programming
Exercise 3.9.
**5.37
( Decimal to binary ) Write a program that prompts the user to enter a decimal
integer and displays its corresponding binary value. Don't use Java's Integer
.toBinaryString(int) in this program.
**5.38
( Decimal to octal ) Write a program that prompts the user to enter a decimal
integer and displays its corresponding octal value. Don't use Java's Integer
.toOctalString(int) in this program.
*5.39
( Financial application: find the sales amount ) You have just started a sales job
in a department store. Your pay consists of a base salary and a commission. The
base salary is $5,000. The scheme shown below is used to determine the commis-
sion rate.
Sales Amount
Commission Rate
$0.01-$5,000
8 percent
$5,000.01-$10,000
10 percent
$10,000.01 and above
12 percent
Note that this is a graduated rate. The rate for the first $5,000 is at 8%, the next
$5000 is at 10%, and the rest is at 12%. If the sales amount is 25,000, the com-
mission is 5,000 * 8%
+
5,000 * 10%
+
15,000 * 12%
=
2,700.
 
Search WWH ::




Custom Search