systemin and systemout should not be used


System.in and System.out should not be used anywhere in the programs except in main and only for testing purposes.  All calculations should be done in a method. 

Note:  To use JUnit, you will need to use Eclipse.  There are videos and slides in the Lectures area to help you learn about Eclipse if you are not using it now.

In this lab, you will be constructing a small part of a program that will simulate the workings of an electronic circuit.  Specifically, you will be implementing a few logic gates that, based on the inputs to the gates, produce a true or false value.  The gates should be created with the following guidelines:

AND Gate

Implements the logical AND function (same as the one in the Boolean expressions)

Has a name

Has an output value (which is initially false)

Has a method that takes two Boolean values and, using them, updates the output value

OR Gate

Implements the logical OR function (same as the one in the Boolean expressions)

Has a name

Has an output value (which is initially false)

Has a method that takes two Boolean values and, using them, updates the output value

3 Input AND Gate

Implements the logical AND function (same as the one in the Boolean expressions)

Has a name

Has an output value (which is initially false)

Has a method that takes two Boolean values and, using them, updates the output value

Has a method that takes three Boolean values and, using them, updates the output value

Debug OR Gate

Implements the logical OR function (same as the one in the Boolean expressions)

Has a name

Has an output value (which is initially false)

Has a method that takes two Boolean values and, using them, updates the output value.  This method should store the values of the parameters and modify the name of the class to include the values of the parameters and the value they produced

This should follow (exactly) the format ||=

Where is a single space and the other values in < > are the values of variables stored in the class. (No < > are in the output.)

e.g.  Or Gate 12 false || true = true

As you looked through that list of requirements, you should have noticed that several of the same elements are showing up again and again.  So, the first thing to be done in the lab is to create a base class LogicGate.   This class will contain a name (String), and a calculated (boolean) value and have methods for accessing those values.  Make sure those classes have the appropriate encapsulation.  The getters should be called getValue and getName and should not take any parameters.  LogicGate should also have a constructor that takes a String (for the name) and that initially sets the output value to false.  The final method in LogicGate should be called performLogic and should take two boolean parameters and return nothing.  Because it is not clear what performLogic should do is this this class, make the method and the class abstract.

Starting this way, makes creating the other classes much easier.  Use inheritance to create a class AndGate and a class OrGate.  If you created these classes and LogicGate correctly, you should only have to implement a constructor and the performLogic method for these classes.  The constructor should only take a String parameter.  (HINT: use super to call LogicGate's constructor.)

The next class to create is And3Gate.  This should also use inheritance.  (Which class should it inherit from?  Picking the wrong one will require you to do more work.)  In this class, create a constructor as with the other classes.  However, this class should append " 3 Input" (watch the spaces) to the name of the gate (i.e. the String passed into the constructor).  (HINT:  super must be the first line of the constructor.  You can, however, manipulate what is passed to super.)  In addition, it should have a method called performLogic that takes three boolean parameters and returns nothing.  This method should calculate the result of the three parameters ANDed together and store the result in the classes output value.

The final class to create is DebugOrGate.  (Which class should this inherit from?)  As before, this should create a constructor that accepts a String.  It will also need to override two existing methods performLogic and getName.  performLogic should do exactly what OrGate's method does except it should record the values of the parameters. (HINT: Use super.) (HINT: Use to instance variables in this class to store the parameter values.)  getName should return a modified version of the name of the class.  DO NOT update the actual name!  Just return the name with additional information attached to it.  The format for the information should be (exactly) ||=

(HINT: if you want to call the parent's getName method, make sure you use super.)

Create JUnit tests for all of your classes except LogicGate.  You only need to test methods implemented in the class.  That is, for And3Gate, you only need to check the constructor (i.e. that getName and getValue return the correct values after creating an object) and the 3 parameter performLogic method.  You do not need to test the methods implemented in the parent's class. 

Request for Solution File

Ask an Expert for Answer!!
Application Programming: systemin and systemout should not be used
Reference No:- TGS0207527

Expected delivery within 24 Hours