Create a new directory for this exercise. Copy the Circle.java
file that
you created as your Exercise 6 solution into this new directory, then
download Money.java and Ex10.java into that
same directory.
Modify the Circle
and Money
classes so that they conform to the UML
diagram below. This means you will need to create Writeable
, and you will
also need to add the specified method to the two classes. You should not
remove any of the existing features of those classes.
Note also the following points:
Writer
is a class from the Java API, defined in the java.io
package. It represents something to which you can write text (standard
output, a file, etc).
The purpose of the writeTo
method is to write a textual representation
of an object to the given Writer
. In the case of Money
objects, if
the amount of money is 2 euros and 7 cents, the string Money: €2.07
should be written, followed by a newline character. In the case of Circle
objects, if the circle radius is 1.5, the string Circle: r=1.5000
should
be written, again followed by a newline.
The writeTo
method can potentially throw the checked exception
IOException
, so you will need to declare this fact using an exception
specification.
To help you check whether you have implemented all of this correctly, you can
use the program in Ex10.java
. If you compile and run this program, it
should generate the following output:
Money: €2.07
Money: €11.80
Circle: r=6.3952
□