Java Reference
In-Depth Information
causes death in laboratory mice. A friend of yours is desperate to lose weight but
cannot give up soda pop. Your friend wants to know how much diet soda pop it
is possible to drink without dying as a result. Write a program to supply the
answer. The input to the program is the amount of artificial sweetener needed to
kill a mouse, the weight of the mouse, and the desired weight of the dieter.
Assume that diet soda contains 1/10th of one percent artificial sweetener. Use a
named constant for this fraction. You may want to express the percent as the
double value 0.001 .
7.
Write a program that determines the change to be dispensed from a vending
machine. An item in the machine can cost between 25 cents and a dollar, in 5-cent
increments (25, 30, 35, . . . 90, 95, or 100), and the machine accepts only a single
dollar bill to pay for the item. For example, a possible sample dialog might be
Enter price of item
(from 25 cents to a dollar, in 5-cent increments): 45
You bought an item for 45 cents and gave me a dollar,
so your change is
2 quarters,
0 dimes, and
1 nickels.
8.
Write a program that reads in a line of text and then outputs that line of text first
in all uppercase letters and then in all lowercase letters.
9.
(This is a better version of an exercise from Chapter 1.) Write a program that
reads in a line of text and then outputs that line of text with the first occurrence
of "hate" changed to "love" . For example, a possible sample dialog might be
Enter a line of text.
I hate you.
I have rephrased that line to read:
I love you.
You can assume that the word "hate" occurs in the input. If the word "hate"
occurs more than once in the line, your program should replace only the first
occurrence of "hate" .
Search WWH ::




Custom Search