March 02, 2019
BY Help Me Our Always0
Comments
Source Code
import java.util.Scanner;
//=====================================================================================================================
class star{
public void star(){
for(int i=1;i<=50;i++){
System.out.print("*");
}
}
}
class OrGate extends star{
int or1,or2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your Two numbers(either(1/0))\n");
or1=Sc.nextInt();
or2=Sc.nextInt();
}
public void or(){
if((or1==0)&&(or2==0)){
System.out.println("Your output is:");
System.out.println("0");
}
else{
System.out.println("Your Output is:");
System.out.println("1");
}
}
}
//======================================================================
class AndGate extends star{
int and1,and2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your Two numbers(either(1/0))\n");
and1=Sc.nextInt();
and2=Sc.nextInt();
}
public void and(){
if((and1==1)&&(and2==1)){
System.out.println("Your output is:");
System.out.println("1");
}
else{
System.out.println("Your Output is:");
System.out.println("0");
}
}
}
//======================================================================
class NotGate extends star{
int not1,not2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your one numbers(either(1/0))\n");
not1=Sc.nextInt();
//not2=Sc.nextInt();
}
public void or(){
if(not1==0){
System.out.println("Your output is:");
System.out.println("1");
}
else if(not1==1){
System.out.println("Your Output is:");
System.out.println("0");
}
else{
System.out.println("Invalid Input");
}
}
}
//======================================================================
class NorGate extends star{
int nor1,nor2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your Two numbers(either(1/0))\n");
nor1=Sc.nextInt();
nor2=Sc.nextInt();
}
public void nor(){
if((nor1==0)&&(nor2==0)){
System.out.println("Your output is:");
System.out.println("1");
}
else {
System.out.println("Your Output is:");
System.out.println("0");
}
}
}
//======================================================================
class NandGate extends star{
int nand1,nand2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your Two numbers(either(1/0))\n");
nand1=Sc.nextInt();
nand2=Sc.nextInt();
}
public void nand(){
if((nand1==1)&&(nand2==1)){
System.out.println("Your output is:");
System.out.println("0");
}
else {
System.out.println("Your Output is:");
System.out.println("1");
}
}
}
//======================================================================
class XorGate extends star{
int xor1,xor2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your Two numbers(either(1/0))\n");
xor1=Sc.nextInt();
xor2=Sc.nextInt();
}
public void xor(){
if(xor1==xor2){
System.out.println("Your Output is");
System.out.println("0");
}
else if(xor1==xor2){
System.out.println("Your Output is");
System.out.println("0");
}
else{
System.out.println("1");
}
}
}
//======================================================================
class XnorGate extends star{
int xnor1,xnor2;
public void getSet(){
Scanner Sc=new Scanner(System.in);
System.out.println("\nEnter your Two numbers(either(1/0))\n");
xnor1=Sc.nextInt();
xnor2=Sc.nextInt();
}
public void xnor(){
if((xnor1==1)&&(xnor2==1)){
System.out.println("Your output is:");
System.out.println("1");
}
else if((xnor1==0)&&(xnor2==0)) {
System.out.println("Your Output is:");
System.out.println("1");
}
else{
System.out.println("0");
}
}
}
//======================================================================
public class Main{
public static void main(String args[]){
System.out.println("Note: You have to give input either 1 or 0");
System.out.println("1. OR Gate");
System.out.println("2.AND Gate");
System.out.println("3. NOT Gate");
System.out.println("4. NOR Gate");
System.out.println("5. NAND Gate");
System.out.println("6. XOR Gate");
System.out.println("7. XNOR Gate");
System.out.println("Which operation would you like to perform:");
int menu;
Scanner In=new Scanner(System.in);
menu=In.nextInt();
switch(menu){
case 1:
OrGate obj1=new OrGate();
obj1.star();
System.out.println("\nOR Gate\n");
obj1.star();
obj1.getSet();
obj1.or();
break;
case 2:
AndGate obj2=new AndGate();
obj2.star();
System.out.println("\nAND Gate\n");
obj2.star();
obj2.getSet();
obj2.and();
break;
case 3:
NotGate obj3=new NotGate();
obj3.star();
System.out.println("\n NOT Gate\n");
obj3.star();
obj3.getSet();
obj3.or();
break;
case 4:
NorGate obj4=new NorGate();
obj4.star();
System.out.println("\nNOR Gate\n");
obj4.star();
obj4.getSet();
obj4.nor();
break;
case 5:
NandGate obj5=new NandGate();
obj5.getSet();
obj5.nand();
break;
case 6:
XorGate obj6=new XorGate();
obj6.star();
System.out.println("\n XOR Gate\n");
obj6.star();
obj6.getSet();
obj6.xor();
break;
case 7:
XnorGate obj7=new XnorGate();
obj7.star();
System.out.println("\n XNOR Gate\n");
obj7.star();
obj7.getSet();
obj7.xnor();
break;
default:
System.out.println("Invalid Input");
}
}
}