Java Reference
In-Depth Information
14.21 (Writing the Word Equivalent of a Check Amount) C ontinuing the discussion in
Exercise 14.20, we reiterate the importance of designing check-writing systems to prevent alteration
of check amounts. One common security method requires that the amount be written in numbers
and spelled out in words as well. Even if someone is able to alter the numerical amount of the check,
it's extremely difficult to change the amount in words. Write an application that inputs a numeric
check amount that's less than $1000 and writes the word equivalent of the amount. For example,
the amount 112.43 should be written as
ONE hundred TWELVE and 43/100
14.22 (Morse Code) Perhaps the most famous of all coding schemes is the Morse code, developed
by Samuel Morse in 1832 for use with the telegraph system. The Morse code assigns a series of dots
and dashes to each letter of the alphabet, each digit, and a few special characters (e.g., period, com-
ma, colon, semicolon). In sound-oriented systems, the dot represents a short sound and the dash a
long sound. Other representations of dots and dashes are used with light-oriented systems and sig-
nal-flag systems. Separation between words is indicated by a space or, simply, the absence of a dot
or dash. In a sound-oriented system, a space is indicated by a short time during which no sound is
transmitted. The international version of the Morse code appears in Fig. 14.26.
Write an application that reads an English-language phrase and encodes it into Morse code.
Also write an application that reads a phrase in Morse code and converts it into the English-lan-
guage equivalent. Use one blank between each Morse-coded letter and three blanks between each
Morse-coded word.
Character
Code
Character
Code
Character
Code
A
.-
N
-.
Digits
B
-...
O
---
1
.----
C
-.-.
P
.--.
2
..---
D
-..
Q
--.-
3
...--
E
.
R
.-.
4
....-
F
..-.
S
...
5
.....
G
--.
T
-
6
-....
H
....
U
..-
7
--...
I
..
V
...-
8
---..
J
W
9
.---
.--
----.
K
-.-
X
-..-
0
-----
L
Y
.-..
-.--
M
--
Z
--..
Fig. 14.26 | Letters and digits as expressed in international Morse code.
14.23 (Metric Conversions) Write an application that will assist the user with metric conversions.
Your application should allow the user to specify the names of the units as strings (i.e., centimeters,
liters, grams, and so on, for the metric system and inches, quarts, pounds, and so on, for the English
system) and should respond to simple questions, such as
"How many inches are in 2 meters?"
"How many liters are in 10 quarts?"
 
 
Search WWH ::




Custom Search