instance of these classes and to pass them to class Calculator according to the
Which format is best suited to internal representation of operands and results?
Since the specification of the problem insists on the importance of the
fractional format, top priority is given to the accuracy of representation of
rational numbers (i.e. those represented by fractions). To simplify the con-
version procedure we decide to adopt a unique internal representation
format. Consequently, we decide to store the numbers internally using the
The internal structure of the calculator component is shown in Figure 6.5.
The main class is Calculator , which implements the main feature of the
calculator, i.e. the four operations and the management of the operands.
The operands are implemented by the Rational class. This class represents
a number as a fraction, i.e. it stores a numerator and a denominator. It
provides methods to add, subtract, multiply and divide two Rational objects.
The Calculator class has two associations to class Rational to represent the
first and second operand. Since at initialization time there are no assigned
values for the operands we decide to adopt zero as the default value of
In this prototype we assume that the standard base is the decimal base.
How do the abstract class Format and its subclasses express the format
parse(number : String) : Rational
toString(number : Rational) : String
getName() : String
Figure 6.5 Class relations for format conversion