COMP204-08B Assignment 4

Due date: Monday, 22nd September

Parsing numbers


This one looks simple: read in a text file, find all the numbers in it, and then simply print out the smallest number, the largest number, and sum of all numbers found. Now here's the hitch: the numbers can be larger than what any of the standard builtin numbers can represent. But at least the numbers follow the following specification, which is a strict subset of the java.math.BigDecimal specification for its String constructor:
BigDecimalString: 
 Sign_opt Significand Exponent_opt

Sign:
 +
 -

Significand:
 IntegerPart . FractionPart_opt
 IntegerPart

IntegerPart:
 Digits

FractionPart:
 Digits

Exponent:
 ExponentIndicator SignedInteger

ExponentIndicator:
 e
 E

SignedInteger:
 Sign_opt Digits

Digits:
 Digit
 Digits Digit

Therefore, once you have located the numbers, you can use this constructor in the BigDecimal class to turn it into a number and compute everything needed. One more hitch: numbers must be separated from other numbers or other text by whitespace or line breaks, i.e. they must be proper "words". So a line "123a456" would not yield any number, whereas a line "123 a 456" would return 123 as minimum, 456 as maximum, and 579 as sum.

What to submit:

One java file containing all you code.
Document your code well.
Use the javadoc @author tag to give your name and ID!

As always, assessment will be based on the following criteria:

  1. Functionality
  2. Reasonable clarity and style of programming.
  3. Reasonable documentation;

More hints:

  1. It is possible to define a single regular expression describing the number specification given above.
  2. Have a look at the RegexTestHarness for inspiration
  3. class BigDecimal
  4. class Pattern