When you learned to speak English, one of the things you learned was how to write the names of numbers in English. Today, we will write a program to do just that (using a simple hash map.) The rules for writing English we will use are outlined in Wikipedia: Names of numbers in English. (Note that these rules allow an optional "and", so you can either write "one hundred one" or "one hundred and one" for 101. We will NOT use the optional "and" to keep things simple.)
Create a lab11 package, and create a class called EnglishNumbers. Create a single field that consists of a HashMap that maps an Integer to a String. The constructor should instantiate the HashMap, and fill in all the number names from zero to twenty, as well as thirty, forty, ... up to 90 (basically a transcription of the table at the top of the Wikipedia web-page.)
Then, write a method called nameNumber which takes a long number as an argument and returns a String. The nameNumber method should figure out the English name of the argument. If the number is negative, precede the name of the number with the word "minus", followed by a blank. You should support all numbers from -999,999,999,999 to +999,999,999. No decimals are required... the argument is an integer, but you need the "long" type to support the larger numbers. Your returned value should be all lower case letters.
For instance, nameNumber(12) should return the string "twelve", and nameNumber(-100000000003) should return the string "minus one hundred billion three".
Do you know a different language? Can you write a new class, like "TurkishNumbers" or "SpanishNumbers" that translates a number into Turkish or Spanish? If your second language has accents or diacritical marks, can you figure out how to look those up and use the Unicode \uXXXX notation to print those characters?
Zip your code in the lab11 package, and submit it on myCourses. This lab is worth 10 points. You will get the full 10 points if your code compiles without warnings, and produces the correct output. The CA's have their own test function that invokes your methods with some pre-defined arguments. The following are reasons for deductions:
Since we don't know all other languages, any (reasonably serious) attempt to code an alternative language class will earn two extra credit points. If you use special characters in this attempt, a third extra credit point will be added. As always, extra credit points can only be used to offset deductions on this lab.