Hi I am trying to create a method that will substitute a value x with a value y in a basic array. Your assistance is much appreciated!

Yeungn

So what do you need help with? Have you tried it yet? Try it and post what you've got and we'll help.

hey thanks for your response. I'm fairly new with Java so I really appreciate your support! I'm working on a project for school that requires a method called createAllCombinations(int i)

The basic idea of the createAllCombinations method is to determine which combinations of constants from the domain, when substituted for each unique variable in the predicate list, make the predicate list true. A single combination of constants is called a possible solution. A possible solution that makes the predicate list true is called a solution. Substituting for “each unique variable” means that when we substitute a constant c for a variable v, we substitute c for all occurrences of v. If there exists at least one solution, then the createAllCombinations method returns true, otherwise it returns false.

Right now this is what I have so far!

``````protected boolean createAllCombinations(int i)
throws ParserException
{
System.out.println("Implement PredicateList.createAllCombinations");
if(variables.length == i)
if(checkToSeeIfTrue())
return true;
else
return false;
/** The variables to be used in this method:
*/
else
{
Constant value;
Constant[] arrayConstant;

Identifier var;
Constant constant;

/** Declaring the iterator and array of constants
*
*/
Iterator<Constant> itr = Domain.iterator();
arrayConstant = new Constant[variables.length];

/** Get all constants from the domain
*
*/
for(int n = 0; n > variables.length-1; n++)
{
value = itr.next();
arrayConstant[n] = value;
System.out.println(arrayConstant[n]);
}
/** Gather the Identifier to swap with the constant
*
*/

var = variables[i];
constant = arrayConstant[i];
i++;
createAllCombinations(i);
/**Substitute the constant we get from the domain for variables[i], wherever it occurs in the predicate list
*
*/
setVariableToValue(var, constant);
return true;

}
}``````

I'm wondering if I can substitute where I get the variable (for example Bob) I would have to take all those values and replace it with a constant. I am not sure how to perform this in Java. Any pointers or hints?