Question: } / / Getter method for distance public int getDistance ( ) { if ( distance = = - 1 ) { / / Ensure

}
// Getter method for distance
public int getDistance(){
if (distance ==-1){// Ensure distance is calculated if not already done
distance = findDistance(startWord, endWord);
}
return distance;
}
// Getter method for the path
public String getPath(){
if (distance ==-1){// Ensure distance is calculated before finding path
distance = findDistance(startWord, endWord);
}
if (distance ==-1){
return "There is no path";
}
if (path.isEmpty()){// Calculate the path if it hasn't been done yet
findPath(startWord, endWord);
}
return String.join("->", path);
}
}
this is the last part of the LevenshteinFinder.java code, for some reason this code its not quite working. It should see something like what is below, but for me after i enter both words i keep getting the error, Error: getDistance has not been run yet. and i dont know why, can i get help and its okay if you need to modify the code but cant modify the main method only the finder, the main one can only have very tiny changes.
* Welcome to the Levenshtein Edit distance solver *
* Please type in two words of the same size that will be used *
* To find a path between them. *
*****************************************************************
What word would you like to start with?
--->Witch
What word would you like to end with?
--->Coven
The distance between your words is 9
The path between your words is : witch->watch->match->march->marcs-
>mares->mores->moves->coves->coven
******************************************************************
Total execution time: 14407ms.
} / / Getter method for distance public int

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!