CIT 591 Assignment 3: Name That Number
Fall 2008, David Matuszek
Write a program that reads in text from the keyboard and displays it on the screen.
If there are any integers in the text, they are replaced by their English word
equivalents. For example, if the input is
Today is September 19, 2008.
then the output should be
Today is September nineteen, two thousand eight.
Scanner to read in "tokens"--words and numbers--from
the keyboard.
hasNextInt() to ask the scanner if the next token it
will return is composed entirely of digits.int by asking the scanner for the nextInt().String by asking the scanner for the next() token.int variable.
n by evaluating the expression
n % 10. 347
/ 10 gives 34).Your program is to read in text from the keyboard. It then prints out the
same text, except that it turns every
integer number between 0 and 9999,
inclusive, into words.
You do not have to worry about floating point numbers, negative numbers, or numbers greater than 9999.
The hasNextInt() method will return false if the
next token is not a "pure" integer; for example, if it like 21st,
or 4:30. You do not need to translate these "almost numbers" into
words. Just print them out as they are.
The program should end when it reads the token *end*. To quit
the program, the user should type in these five characters as a single token.
We will be using a program to do part of the grading. Here are some rules you must follow to satisfy our grading program:
ninety,
not ninty. If you are unsure of the spelling, use a dictionary. two thousand eight.private. Here are the methods you must have. (You may have additional methods if you wish.)
String nameOf(int number)number in the range 0 to 9999,
return a String of words representing that number. Words must be separated
by exactly one space. (This method calls the other methods, as necessary,
in order to do its job.) String nameOfDigit(int number)number in the range 0 to 9,
return a String consisting of a single word representing that number (zero through nine). String nameOfTensDigit(int number)number in the range 1 to 9,
return a String consisting of a single word representing that number
of tens. That is, return one of the words ten, twenty, thirty,
..., ninety. String nameOfTeens(int number)10 to 19, return
a String consisting of a single word representing that number. That is,
return one of the words ten, eleven, twelve,
..., nineteen. The program we will use to grade your program is very picky. The words returned by each of your methods must be spelled correctly. The String must not begin or end with a space (or any other whitespace). If you don't follow these rules, it is an error, and you will lose points.
I have not talked about the switch statement in class. It isn't
necessary for this assignment, but it makes some of the methods easier. You
can use it if both you and your partner understand it.
A note about Eclipse. When you type into the Console area in Eclipse, your typing will go in the correct place (at the end of whatever is already there), regardless of where it looks like the cursor is. This is a minor bug in Eclipse.
You can type multiple lines into your program, and the output will come out in the same area. It will not come out in neat lines, and there is no easy way to fix this, so don't worry about it.
Grading will be based on getting the output of each method exactly correct, as judged by our grading program. In addition, you are required to format your program according to Java standards (Eclipse will do this for you if you tell it to, but it's your responsibility to tell it to.) You are also required to choose good variable names, and to capitalize them according to Java conventions (Eclipse will not do this for you.)
You will have a partner for this assignment. The two of you should turn in one copy of your program. Both your names should be in a comment in the program. In addition, whichever of you turns the program in, should put your partner's name in the comments in Blackboard.
Your program is due before midnight, Thursday September 25. Zip up the entire directory for this project, and submit via Blackboard.