Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*Here is the beginning of a program that:
- * Asks the user what logic gate they want to choose
- * Asks the input for input A and B
- * uses a subroutine called andGate that accepts values for input A and B
- * The subroutine then produces the correct output depending on the input
- *
- * Develop the code to:
- * include subroutines for NOT, OR, NOR, NAND and XOR gates
- * ask the user to choose what gat they want to choose and produce the correct output.
- *
- * Extension:
- * Use a loop so that the user can keep choosing gates until END is entered.
- *
- */
- public class logicGates
- {
- public static int andGate (int a, int b){//AND subroutine
- if (a==1 && b==1){
- return 1;
- }
- else{
- return 1;
- }
- }
- public static void main (String args[]){
- System.out.print("\u000C");
- String gate;
- int aInput, bInput;
- Scanner input =new Scanner (System.in);
- System.out.println("What is the input for A? ");
- aInput = input.nextInt();
- System.out.println("What is the input for B? ");
- bInput = input.nextInt();
- System.out.println("choose a gate");
- gate = input.next();
- if (gate.equals("and")){
- System.out.println("The output is "+andGate(aInput, bInput)); //what happens with this code?
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement