title: Changing the value of a boolean variable with class methods?
body: <p>So I am messing around with java and came across a problem with some code I am trying to write.</p>
  
  <p>I have made a class called <code>LogicGate</code> in this class there are methods to set the state of the instance of <code>LogicGate</code> to either true or false.</p>
  
  <p><code>LogicGate</code> only has one attribute and its a boolean value true or false.</p>
  
  <p>All the methods seem to work but the one (called not()) where I am changing the boolean value to false if true and true if false.</p>
  
  <p>The code changes the value the first time from true to false but the second time it seems to ignore the if statement. </p>
  
  <pre><code>//Main
  
  public class main {
  
      public static void main(String[] args) {
  
          LogicGate logicGate = new LogicGate(true);
  
          System.out.println(logicGate.state());
          System.out.println("");
  
          logicGate.not(logicGate);
          System.out.println("");
  
          System.out.println(logicGate.state());
          System.out.println("");
  
          logicGate.not(logicGate);
      }
  
  }
  
  //Class Logicgate
  
  
  public class LogicGate {
      //The attribute for the for the object
      private boolean state;
  
      //Creating the constructor for the object logic gate 
      public LogicGate(boolean logicGateState) {
          state = logicGateState;
      }
  
      //This method changes the state of the Logic Gate
      public  void not(LogicGate obj) {
  
          //Saving the current state of the logic gate
          boolean currentState = obj.state();
  
          System.out.println("....." + currentState);
  
          //Checks the state of the object instance and changes it accordingly
          if(currentState = true) {
              obj.negate(obj);
              System.out.println("The state has changed to: " + obj.state() + " Should be false");
          }
          else if(currentState = false) {     
              obj.set(obj);
              System.out.println("The state has changed to: " + obj.state() + " Should be true");
  
          }
  
  
      }
  
      //Sets the state of the object boolean variable to true 
      public  void set(LogicGate obj) {
          obj.setState(true);
  
      }
  
  
  
      //Sets the state of the object boolean variable to false 
      public  void negate(LogicGate obj) { 
          obj.setState(false);
  
      }
  
      //This method will return the state of the object
      //it can be either true or false 
      public boolean state() {
          return state;
      }
  
      //Sets the boolean attribute 
      public void setState(boolean state) {
          this.state = state;
      }
  
  
  }
  </code></pre>
  
  <p>The boolean value should just change every time the not method is called.</p>
  
  <p>The final line of the code should say <code>The state has changed to: true Should be true</code>.</p>
  
  <p>The result I am getting is:</p>
  
  <pre><code>true
  
  .....true
  The state has changed to: false Should be false
  
  false
  
  .....false
  The state has changed to: false Should be false
  </code></pre>