Java Reference
In-Depth Information
Enable the user to enter new values.
Enable the user to delete erratic values.
Enable the user to switch to previous logs.
In accordance with the design guidelines, persistent storage shall be performed in the background.
Day Log
In order to provide the desired functionality, we need two main data structures:
• A data structure for the current day, holding the date and the values and times for the day's
measurements
• A data structure storing all the days persistently
Thus, the day log data structure needs a field holding the date and a list of the time and value pairs. The
date is stored in the integer variable date, holding the day of the month in the lowest byte, the month in
the second-lowest byte, and the year in the two upper bytes. We are using this format instead of the
Date or Calendar object for simplified comparison, required for keeping the log entries in the right
order. To store the pairs, a local class Entry is used, consisting of two integer values: time and
value . Similar to the date field, we use an integer to represent the time, measured in minutes since
midnight. Again, the main reason is simpler comparison. We also use the DayLog class to define the
minimum and maximum value constants for the graphics display (see Figure 9.2 ) .
Figure 9.2. The DayLog constants.
Our basic DayLog class looks as follows:
import java.io.*;
import java.util.*;
 
 
Search WWH ::




Custom Search