Lab 1

Reading

Class hierarchies in LL Sections 7.1, 7.2, 7.3. Boolean gates and circuits in SG Sections 4.3 and 4.4.

Design

You will be asked to write some Java code. There is no unique correct solution: you have some freedom in interpreting the specifications. Make any reasonable assumptions.

Part I

Implement the following class hierarchy:
abstract class Gate ...
abstract class UnaryGate extends Gate ...
abstract class BinaryGate extends Gate ...
class And extends BinaryGate ...
class Or extends BinaryGate ...
class Not extends UnaryGate ...
Provide a driver that tests every combination of inputs to the And, Or, and Not gates.

Part II

Figure 4.17 of the SG book shows the design of the OneBitComparator gate; Figure 4.18 shows how to use the OneBitComparator gate to compare numbers of arbitrary length.
  1. Extend your program above with a new gate called OneBitComparator. Test that your implementation works correctly.
  2. Write a collection of Java methods to realize the following: read two numbers from the keyboard input, convert the numbers to a binary representation, and use the OneBitComparator as described in Figure 4.18 to check the equality of the two numbers.


Visited times since March 23, 1999 (or the last crash).