Java Reference
In-Depth Information
java Reverse HelloPrinter. java
then the contents of HelloPrinter.java are changed to
retnirPolleH ssalc cilbup
{
)sgra ] [gnirtS(niam diov citats cilbup
{
wodniw elosnoc eht ni gniteerg a yalpsiD //
;)"!dlroW ,olleH"(nltnirp.tuo.metsyS
}
}
Of course, if you run Reverse twice on the same file, you get back the
original file.
524
525
΢΢΢ Exercise P11.8. Write a program that replaces all tab characters Ó\tÓ in
a file with the appropriate number of spaces. By default, the distance
between tab columns should be 3 (the value we use in this topic for Java
programs) but it can be changed by the user. Expand tabs to the number
of spaces necessary to move to the next tab column. That may be less
than three spaces. For example, consider the line containing
Ð\t|\t||\t|Ñ . The first tab is changed to three spaces, the second to
two spaces, and the third to one space. Your program should be executed
as
java TabExpander filename
or
java -t tabwidth filename
΢
Exercise P11.9. Modify the BankAccount class to throw an
IllegalArgumentException when the account is constructed with a
negative balance, when a negative amount is deposited, or when an amount
that is not between 0 and the current balance is withdrawn. Write a test
program that causes all three exceptions to occur and that catches them all.
΢΢ Exercise P11.10. Repeat Exercise P11.9, but throw exceptions of three
exception types that you define.
Search WWH ::




Custom Search