Java Reference
In-Depth Information
΢΢΢G Exercise P5.17. Write a graphics program that asks the user to specify
the radii of two circles. The first circle has center (100, 200), and the
second circle has center (200, 100). Draw the circles. If they intersect,
then color both circles green. Otherwise, color them red. Hint:
Compute the distance between the centers and compare it to the radii.
Your program should draw nothing if the user enters a negative radius.
In your exercise, define a class Circle and a method boolean
intersects(Circle other) .
Additional programming exercises are available in WileyPLUS.
PROGRAMMING PROJECTS
΢΢΢ Project 5.1 Implement a combination lock class. A combination lock has
a dial with 26 positions labeled A ș Z. The dial needs to be set three
times. If it is set to the correct combination, the lock can be opened.
When the lock is closed again, the combination can be entered again. If a
user sets the dial more than three times, the last three settings determine
whether the lock can be opened. An important part of this exercise is to
implement a suitable interface for the CombinationLock class.
΢΢΢ Project 5.2 Get the instructions for last year's form 1040 from
http://www.irs.ustreas.gov [ 2 ]. Find the tax brackets that were used last
year for all categories of taxpayers (single, married filing jointly, married
filing separately, and head of household). Write a program that computes
taxes following that schedule. Ignore deductions, exemptions, and
credits. Simply apply the tax rate to the income.
224
225
ANSWERS TO SELF-CHECK QUESTIONS
1.
If the withdrawal amount equals the balance, the result should be a zero
balance and no penalty.
2.
Only the first assignment statement is part of the if statement. Use braces
to group both assignment statements into a block statement.
3.
(a) 0; (b) 1; (c) an exception is thrown
Search WWH ::




Custom Search