(→Solution 1: AndGate3i defined as a subclass of AndGate2) |
(→Solução 2: AndGate3c defined as a composition of two AndGate2) |
||
Line 105: | Line 105: | ||
In this solution, the 3-input gate is defined as a composition of 2-input gates. Note that the A-input of the second gate is updated whenever the inputs of the first gate are changed. | In this solution, the 3-input gate is defined as a composition of 2-input gates. Note that the A-input of the second gate is updated whenever the inputs of the first gate are changed. | ||
+ | {{CollapsedCode|Ficheiro '''AndGate3c.java'''| | ||
<java5> | <java5> | ||
/** Logical AND gate with 3 inputs (composition). */ | /** Logical AND gate with 3 inputs (composition). */ | ||
Line 236: | Line 237: | ||
} | } | ||
</java5> | </java5> | ||
+ | }} | ||
[[category:Ensino]] | [[category:Ensino]] | ||
[[category:PO]] | [[category:PO]] | ||
[[category:PO Exemplos]] | [[category:PO Exemplos]] |
Defina uma nova classe que represente uma porta lógica AND com três entradas. Esta classe deve chamar-se AndGate3 e apresenta a mesma funcionalidade que a de duas entradas. A apresentação (toString) é A: valor B: valor C: valor.
A classe AndGate3 deve ser definida reutilizando o conceito AndGate2 (definido no Exercício 1).
Adapte a função main definida anteriormente, por forma a integrar alguns testes com a nova porta lógica.
In this solution we observe that the operation is a specialization of the previous one. This allows us to reuse the previous functionality.
Ficheiro AndGate3i.java |
---|
{{{2}}} |
In this solution, the 3-input gate is defined as a composition of 2-input gates. Note that the A-input of the second gate is updated whenever the inputs of the first gate are changed.
Ficheiro AndGate3c.java |
---|
{{{2}}} |