jkembo 0 Unverified User

Good morning everyone,

I have a small problem here. I tried to code a piece of program which allows users to construct logic formula. (E.g A V NOT(B))

When the button NOT (unary connective) is pressed 2 times then this happens: NOT(NOT()), using a static recursive method called Rec returning the string and has 2 following parameters:

--> int counter : the number of time the button has been clicked
--> string strConnective: the name of the button pressed(E.g NOT).

But the problem is when another button than NOT is pressed (E.g[path]<F>) which is also an unary connective, the output is not updating, however the output changes to [path]<F>( [path]<F>()) instead of having the correct output NOT(NOT([path]<F>())).


recursive method REC

public static String Rec (int counter, String strConnective){
	if (counter==0) return "";
	else {
				
	counter--;
	strFormulaContent=strConnective+("+Rec(counter,strConnective)+")";
	return  strFormulaContent;
				
	   }
	}

actionPerformed method which is overridden in my main class

public void actionPerformed(ActionEvent e) {
	
	//If statement for NOT button	
	if (e.getSource().equal(not_button)){	

			if(formula_text_JT.getText().equals("")) 
				not_counter=0;
			
			not_counter++;
			if (not_counter!=0){
			
formulaStrings=Rec(not_counter,e.getActionCommand());
				formula_text_JT.setText(formulaStrings);
      }

I spend the all the day to figure it out but no success at all.. Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.