Using recursion, complete the body of the following static method. [JAVA] /** *
ID: 3858865 • Letter: U
Question
Using recursion, complete the body of the following static method. [JAVA]
/**
* Refactors the given {@code Statement} by renaming every occurrence of
* instruction {@code oldName} to {@code newName}. Every other statement is
* left unmodified.
*
* @param s
* the {@code Statement}
* @param oldName
* the name of the instruction to be renamed
* @param newName
* the new name of the renamed instruction
* @updates s
* @requires [newName is a valid IDENTIFIER]
* @ensures <pre>
* s = [#s refactored so that every occurrence of instruction oldName
* is replaced by newName]
* </pre>
*/
public static void renameInstruction(Statement s, String oldName,
String newName) {...}
Using the method above, complete the body of the following static method.
/**
* Refactors the given {@code Program} by renaming instruction
* {@code oldName}, and every call to it, to {@code newName}. Everything
* else is left unmodified.
*
* @param p
* the {@code Program}
* @param oldName
* the name of the instruction to be renamed
* @param newName
* the new name of the renamed instruction
* @updates p
* @requires <pre>
* oldName is in DOMAIN(p.context) and
* [newName is a valid IDENTIFIER] and
* newName is not in DOMAIN(p.context)
* </pre>
* @ensures <pre>
* p = [#p refactored so that instruction oldName and every call
* to it are replaced by newName]
* </pre>
*/
public static void renameInstruction(Program p, String oldName,
String newName) {...}
Explanation / Answer
Below is your method impleementation in Java. Please let me know in comments if you have any issues.: -
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.