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

String cost, A string S is said to be "Super ASCII", if it contains the cha...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci

Fibonacci in windows assmbly language, Write an assembly program that compu...

Write an assembly program that computes Fibonacci numbers 2-5. a. Assume Fib(0)=0 and Fib(1)=1. b. Store Fib(2) in EAX, Fib(3) in EBX, Fib(4) in ECX and Fib(5) in EDX. c. Use a LOO

Use case diagram incremental development, Introduction This assignment ...

Introduction This assignment builds on your application, produced in Assignment 1, which holds a list of cabins, which can be either read in from a text file or just hard coded

Explain inheritance and polymorphism in lingo programming, Question: (a...

Question: (a) Explain the concepts of Inheritance and Polymorphism in Lingo programming. (b) Write short descriptions on parent scripts and child objects in Lingo object

Complex roots, We will be assuming here that our roots are of the form, in ...

We will be assuming here that our roots are of the form, in this case, r 1,2 = l + mi If we take the first root we'll find the following solution. x l + m i It i

Selection structure, Name : Jaya Malathy IC No : 99011460923 Quiz 1 : 20....

Name : Jaya Malathy IC No : 99011460923 Quiz 1 : 20.5 Quiz 2 : 22.5 Quiz 3 40.5 Total marks = 83.5 Name IC No Quiz1 Quiz2 Quiz3 Grade --- ---- ---- ---- ---- ---- Jaya 990

Asp.net support for ajax and javascript intellisense, ASP.NET Support for A...

ASP.NET Support for AJAX and JavaScript IntelliSense IntelliSense for Enthusiasm JScript makes it accessible client-script selection components in the value manager in Vision Facil

Shell script to find a particular pattern from the file, Normal 0 ...

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

Explain the various tools for software implementation, Problem 1. What ...

Problem 1. What are the potential advantages of treating two related classes as subclasses of some superclass? 2. Explain the various tools for software implementation 3.

Phonebook entry, The first task is to extend the  NeoPhoneBookEntry and  Ne...

The first task is to extend the  NeoPhoneBookEntry and  NeoPhoneBook classes to accommodate for  four additional contact  details:  Ringtone,  Vibration Pattern,  Led Pattern  and

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