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

Shell script convert the given amount into words, Normal 0 fals...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Excel, basic steps involved in spreadsheet developement

basic steps involved in spreadsheet developement

Create program that displays levels of the fractal structure, In this Proje...

In this Project your task is to create a program that displays various levels of the fractal structure of the so called square shaped Sierpinski-carpet. The display of level 4 is s

Wap for intelligent agent able to play block dominoes game, Objective: ...

Objective: In a programming language of your choice, write an intelligent agent able to play block Dominoes against a player. Together with this assignment you will find two pa

Python, Write a function lastfirst() that takes a list of strings as a para...

Write a function lastfirst() that takes a list of strings as a parameter. Each string in the list has the format ''Last, First'' where Last is a last name and First is a first nam

Example of undetermined coefficients, Example :  Solve the following differ...

Example :  Solve the following differential equation. y (3)   -  12 y''+48 y' + 64 y = 12 - 32 e -8t + 2 e 4t Solution :    We first require the complementary solution

We are looking for on-call developers, Pre-order integration on Shopify sto...

Pre-order integration on Shopify store We are looking for on-call developers who can integrate Celery on client Shopify stores. Requirements a) Contented editing Shopify them

Write a program that lets the user play an adventure game, Let the player (...

Let the player (denoted U in the diagram below) navigate around the board until she wins the game by finding the exit or is killed by a monster. A player begins the game with a sli

Mathematical expression of linear programming problem, A Consultant Dietici...

A Consultant Dietician provides diet and nutritional advice to clients. A client's diet requires that all the food s/he eats come from one of the four "basic food groups" (chocolat

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