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

Write a function, together with an appropriate test program (function or script)

ID: 652236 • Letter: W

Question

Write a function, together with an appropriate test program (function or script), which will take a string as input and additional arguments which specify the changes to be made to the script. The minimum (3) alterations which your function is required to be able to make to the given string are (a) REVerse order of letters, (b) REMove spaces, (c) INVerse case. Your function should be able to take between 0 and 3 modifiers and apply all modifiers to the string provided. There is no ordering mandated; the modifiers may appear in any sequence. Your test output implemented using a script file should provide at least one example demonstrating each of the modifiers and at least (2) different numbers of arguments. Your function should check for a valid number of arguments, but it is not required that you validate each argument individually.

SAMPLE OUTPUT

>> str1 = ex2_mod_string(

Explanation / Answer

import java.io.*;

class a
{
   String ex2_mod_string(String s1, String s2, String s3)
   {
       if (s2.Equals("REV") || s3.Equals("REV"))
       {
           STring reverse;

           int length = s1.length();
           for ( int i = length - 1 ; i >= 0 ; i-- )
               reverse = reverse + s1.charAt(i);

               s1=reverse;
       }

       if (s2.Equals("INV") || s2.Equals(""))
       {
          
           String t = "";
           for (int x = 0; x < str.length(); x++)
           {
               char c = s1.charAt(x);
               boolean check = Character.isUpperCase(c);
               if (check == true)
                   t = t + Character.toLowerCase(c);
               else
                   t = t + Character.toUpperCase(c);
           }
           s1=t;
       }
       return (s1);
   }


};
class dt_str
{
   public static void main(String[] args)
   {
       String s1, s2, s3, str1;
       DataInputStream o = new DataInputStream(System.in);

       System.out.println("Enter String");
       s1=o.readLine();

       System.out.println("Enter first Operation on string");
       s2=o.readLine();

       System.out.println("Enter second Operation on string");
       s3=o.readLine();

       str1= ex2_mod_string(s1, s2, s3);

       System.out.println(str1);

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote