and gate- or gate-logical-program , Programming Languages

Assignment Help:

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. 


Related Discussions:- and gate- or gate-logical-program

Identify the type of addressing, specify the function of the instruction an...

specify the function of the instruction and also specify whether its right or wrong-: (5) 1) MOV [BX],AX? Register Indirect addressing 2) MOV CX,[BX+DI]?Base plus index add

Program for hold details of all the cabins for travellers, Scenario A ca...

Scenario A campsite provides cabins for travellers to stay in overnight. A 'cabin' is a small wooden hut, containing bunk beds, table and chairs, a heater, and a small cookin

Discuss the php operators, Question 1 Explain the history of Internet ...

Question 1 Explain the history of Internet Question 2 What are the advantages of DHTML? Question 3 Explain the concept of DOM Question 4 How does AJAX work

Dbms, 2. Design an ER diagram for an IT training group database that will m...

2. Design an ER diagram for an IT training group database that will meet the information need’training programme. Clearly indicate the entities, relationships and the key constrain

What is an authentication subsystem, Question: (i) All Security authen...

Question: (i) All Security authentication mechanism that run on the TRU64 Unix Operating system run under the Security Integration Architecture (SIA ) layer. Explain with di

Design and create a new class, You are to design and create a new class cal...

You are to design and create a new class called SelectCallDataDialog, which opens by clicking browse  buttons for selection of ringtones,  vibrations or leds. Depending on which th

Read Multiple Text Files, How to read datasets in multiple text files in an...

How to read datasets in multiple text files in an non interactive program?

Write a function that will read the atoms for a protein, Write a function r...

Write a function readPDBfile('filename') that will read the atoms for a protein stored in a PDB file, whose name is provided as an input to the function (note that this name should

develop a page to indicate distinct attributes, 1.  Develop a page to indi...

1.  Develop a page to indicate distinct attributes of Font tag. 2.  Develop a page to indicate different attributes: bold, italics, underline. 3.  Design a page with backgrou

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd