Java Reference
In-Depth Information
model, i.e. how the calculator internally represents operands and results,
how it supports multiple format conversions, and how it performs arithmetic
operations. The latter problem is related to the definition of the commands
that the user of the calculator can use to interact with it.
The calculator must be able to execute the four operations (!, 0,
) on
two operands. For this purpose, the calculator has two registers. The first
register always stores the last operand inserted by the user or the result of an
operation. The second register stores the previous operand inserted by the
user and it is empty after the execution of an operation.
Some of the operations of the calculator can generate an error, e.g. wrong
format for a number. The operations must be atomic, in the sense that they
preserve the coherence of the state. In case of error, the previous value of
the registers must be restored.
The essential feature of the calculator is the capability to switch from one
representation format to another. The representation format is a generic
concept, which can be separated into three specific formats (see Figure 6.3):
fractional, fixed point and floating point. The format determines how the
numbers entered by the user are parsed and how the numbers stored in the
calculator are printed.
The user interface that is developed in this iteration is a text-based
command line. Available commands are described in Table 6.3. After each
command the user interface must report to the user the result and the
status of the calculator, i.e. the value of the registers according to the
current representation format, and the indication of the current selected
format.
+
,
6.4.2
Design
We consider first the problem of changing format. It must be possible to
change the behaviour of the calculator in terms of operand parsing and
result printing.
Format
Fractional
FixedPoint
FloatingPoint
Example: 7.5*10 1
Example: 3/4
Example : 0.75
Figure 6.3 Analysis of representation format issues
 
Search WWH ::




Custom Search