Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program gives a word for example \"grade\" and user has to come up with another

ID: 3637793 • Letter: P

Question

Program gives a word for example "grade" and user has to come up with another word changing ONLY one letter OR ADDING/SUBTRACTING one letter at the time form word "grade" (it does not matter which one- for example. grade=>grace=>race=>ace=>ice and so on).If the word imputed by user is different by two letters or is longer/shorter by more than one letter and error will occur. My question is how can I program such a code so that is checks two words and tells me if the CORRECT change has been made.

Explanation / Answer

the distance between two words canbe computed using dynamic programming. Check cormen for edit distance programs. If edit distance is 1 then user entered a correct word else not. try using this public class LevenshteinDistance { private static int minimum(int a, int b, int c) { return Math.min(Math.min(a, b), c); } public static int computeLevenshteinDistance(CharSequence str1, CharSequence str2) { int[][] distance = new int[str1.length() + 1][str2.length() + 1]; for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote