Write the following in JAVA code, NOT scheme 8 (convert command string) This fun
ID: 3738252 • Letter: W
Question
Write the following in JAVA code, NOT scheme
8 (convert command string) This function applies a function to string that is determined by looking up command. Consider this application of the cond form that uses a symbol to determine a message: (define (lookup -msg tag) (cond Ceq? tag 'hello) "Hello world") (Ceq? tag 'goodbye) "Goodnight, Moon") ((eq? tag 'scuzz) "You are a scuzz bucket") (else (string-append "Unknown command: " In this particular case, command should correspond to the following symbols 'upper returns an uppercase version of string 'lower returns a lowercase version of string 'reverse returns a reversed version of string 'size returns the number of characters in string . If none are matched, simply return string.Explanation / Answer
As per the chegg guideline, please post one question per post.
Please find my implementation of Q8.
Please rate my answer it it helped you!!
public static String convert(String command, String str) {
switch(command) {
case "upper":
return str.toUpperCase();
case "lower":
return str.toLowerCase();
case "reverse":
return new StringBuffer(str).reverse().toString();
case "size":
return Integer.toString(str.length());
default:
return str;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.