Java Reference
In-Depth Information
public HardDisk(Bus bus) {
this .bus # bus;
}
BufferedReader lineReader; // the line reader of the file
void execute() {
if (bus.command.equals(Bus.FOPEN)) {
try {
lineReader # new BufferedReader(
new InputStreamReader
( new FileInputStream(bus.data)));
}
catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
}
catch (IOException ioe) { ioe.printStackTrace(); }
bus.command # Bus.ACK;
}
else if (bus.command.equals(Bus.FCLOSE)) {
try {
lineReader.close();
}
catch (IOException ioe) { ioe.printStackTrace(); }
bus.command # Bus.ACK;
}
if (bus.command.equals(Bus.FREAD)) {
try {
String line;
if ((line # lineReader.readLine()) ! # null )
bus.data # line;
else
bus.data # "";
}
catch (IOException ioe) { ioe.printStackTrace(); }
bus.command # Bus.ACK;
}
}
}
5.6.4
Test
We define two tests. The first test exercises only the I
O related instructions.
The second test also exercises the storage instructions. The first test asks for
two numbers on the display and reads them from the keyboard, then sums
them and prints the result onto the display. The instructions of the program
are described in Table 5.7.
The second test simulates the bootstrap program of a computer. It is the
first program executed when the computer is turned on and has the purpose
 
Search WWH ::




Custom Search