Java Reference
In-Depth Information
Remember to use escape sequences.
178
179
΢΢Exercise P4.17. Your job is to transform numbers 1, 2, 3, È, 12
into the corresponding month names January, February, March,
. . ., December . Implement a class Month whose constructor
parameter is the month number and whose getName method returns the
month name. Hint: Make a very long string ÐJanuary February
March È Ñ , in which you add spaces such that each month name has the
same length. Then use substring to extract the month you want.
΢΢Exercise P4.18. Write a class to compute the date of Easter Sunday. Easter
Sunday is the first Sunday after the first full moon of spring. Use this
algorithm, invented by the mathematician Carl Friedrich Gauss in 1800:
1. Let y be the year (such as 1800 or 2001).
2. Divide y by 19 and call the remainder a . Ignore the quotient.
3. Divide y by 100 to get a quotient b and a remainder c .
4. Divide b by 4 to get a quotient d and a remainder e .
5. Divide 8 * b + 13 by 25 to get a quotient g . Ignore the
remainder.
6. Divide 19 * a + b Ċ d Ċ g + 15 by 30 to get a remainder
h . Ignore the quotient.
7. Divide c by 4 to get a quotient j and a remainder k .
8. Divide a + 11 * h by 319 to get a quotient m . Ignore the
remainder.
Search WWH ::




Custom Search