So I'm currently trying to construct Sentences in Propositional Logic in java but I ran into a problem with what is probably basic Java but I've tried researching it and I don't know what's actually wrong.
The problem I'm running into is that when I construct a new Complex Sentence (which has a binary connective, a left side, and a right side) it changes my old sentences. How can it change previous instances if I'm initiating a brand new one and not even adding it to the KB(Knowledge Base)? When I ran the debugger it looks like when the new 2nd sentence is being constructed, it still uses the old instance, as the old instance was the "this" in the debugger variables.
Here is my main method:
public static void main(String[] args) {
runModusPonens();
}
public static void runModusPonens(){
KB modusKB=new KB();
Symbol p=modusKB.intern("P");
Symbol q=modusKB.intern("Q");
modusKB.add(p);
Sentence im=new ComplexSentence(LogicalConnective.IMPLIES,p,q);
modusKB.add(im);
modusKB.printWorld();
Sentence i=new ComplexSentence(LogicalConnective.AND,q,p);
modusKB.printWorld();
}
**The output is:
First modusKB print out:
P
(P IMPLIES Q)
Second modusKB print out (after the 2nd sentence was created)
P
(Q AND P) //-->Should still be (P IMPLIES Q)**
And my ComplexSentence class
public class ComplexSentence implements Sentence{
//Sentence structure: leftSide(left hand side sentence) binarycon(connective) rightSide(right hand side sentence)
public static LogicalConnective binarycon;
public static Sentence leftSide;
public static Sentence rightSide;
public ComplexSentence(LogicalConnective connective,Sentence left, Sentence right){
binarycon=connective;
leftSide=left;
rightSide=right;
}
public String toString() {
return "("+this.leftSide+" "+this.binarycon+" "+this.rightSide+")";
}
}
Note: Sentence interface doesn't have anything in it yet so can't be it.