PA5: Dukes Translate (Numbers and Strings)
Part A (30 pts): Due Monday, Nov 14 at 11:59 PM
Submit only your JUnit tests (DukesTranslateTest.java) via Web-CAT.
Late work will not be accepted. If you do not complete Part A by Monday, Nov 14th at 11:59 PM, you will receive a zero for Part A.
Part B (70 pts): Due Friday, Nov 18 at 11:59 PM
Submit DukesTranslate.java and DukesTranslateTest.java via Web-CAT.
- -25% on Saturday, Nov 19 by 11:59 PM
- -50% on Sunday, Nov 20 by 11:59 PM
- Not accepted afterwards
You may (and should) revise your test cases in your final submission.
Honor Code
This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139/149, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.
- Use methods in the String class to solve problems.
- Build new strings from characters and substrings.
- Calculate statistics or properties of a given string.
- Analyze string contents using a Scanner in a loop.
- Convert strings to and from primitive data types.
Requirements
Our translator will depend on the following methods defined in the DukesTranslate class. You may find it useful to implement additional methods to simplify your code, but doing so is not required.
- analyze – given a string, this method counts the number of characters, words, and newlines in the text, returning an array of these three counts. Note that a "word" is any sequence of characters separated by white space. (Hint: Scanner)
Example: analyze("This is the first line.\nThis is the second.") -> {43, 9, 1}
- convert – given a string, a conversion factor, and two strings representing units of measurement, this method returns a new string with every number in the original string multiplied by the conversion factor, formated to one decimal place, and every instance of the old unit replaced with the new unit. Note that the original punctuation must be preserved. (Hint: StringBuilder)
Example: convert("The cat weighs 8 lbs, but the dog weighs 52 lbs.", 0.453592, "lbs", "kg") -> "The cat weighs 3.6 kg, but the dog weighs 23.6 kg."
- jmuIt – given a string, this method returns a new string with every word that was in the original string, but modified such that any word with one or more 'm' or 'M' characters in it now starts with a 'j' and ends with a 'u'.
Example: jmuIt("Hi Mom") -> "Hi jMomu"
- separate – given a string, this method creates an array of "sentences" found in that string. Sentences may end with '.', '!', or '?', and they are always followed by whitespace unless it's the last sentence. Each index in the resulting array holds a string representing one sentence in the original text. Any white space characters (as defined by Java) between sentences should be removed. If a partial sentence at the end of the string does not end with a punctuation mark, it is still considered a separate sentence and should be included at the end of the array.
Example: separate("Hello world. Goodbye now") -> {"Hello world.", "Goodbye now"}
Note: You may NOT use ArrayList or other Java features we haven't yet seen in this course.
- translate – given an array of acronyms, an array of definitions, and a string of text, this method replaces every instance of an acronym in the text with its corresponding definition. You may assume that the two arrays will be the same length.
Example: translate({"JMU", "CS"}, {"James Madison University", "Computer Science"}, "JMU CS rocks!") -> "James Madison University Computer Science rocks!"
Before implementing these methods, you are strongly encouraged to create stubs first, submit them to Web-CAT, and make sure your code compiles on the server. That way, you won't waste any time implementing code for incorrect method signatures.
Clarifications
- None of the above parameters will be null. You can expect all the parameter values to be reasonable.
- Strings will not have extra spaces; there will only be one space between each word and each sentence.
- Punctuation not at the end will allways be followed by whitespace; you won't have to handle "lbs,lbs".