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

Java code Modify the following code so it has at least the same capabilities, bu

ID: 3821762 • Letter: J

Question

Java code

Modify the following code so it has at least the same capabilities, but with a better design (ex:

no repetition, but you can find other flaws below). You are free to enable the code to do more,

and you are not obligated to provide the exact same API as the existing class:

public class Poor {

// set the appropriate variables before calling the function

public static String low, high, fTarget, lTarget;

public static void print(int func, String[] firsts, String[] lasts, String[] emails) {

if (func == 1)

for (int i = 0; i < lasts.length; ++i)

if (lasts[i].compareTo(low) >= 0 && lasts[i].compareTo(high) <= 0)

   System.out.println(lasts[i] + ", " + firsts[i] + ": "  + emails[i]);

if (func == 2)

for (int j = 0; j < lasts.length; ++j)

if (firsts[j].equals(fTarget) && lasts[j].equals(lTarget))

  System.out.println(lasts[j] + ", " + firsts[j] + ": "  + emails[j]);

}

}

Explanation / Answer

HI, Please find my code.

public class Poor {

   // set the appropriate variables before calling the function

   public static String low, high, fTarget, lTarget;

   public static void print(int func, String[] firsts, String[] lasts, String[] emails) {

      

       for (int i = 0; i < lasts.length; ++i) {

          

           if(func == 1 &&

                   lasts[i].compareTo(low) >= 0 && lasts[i].compareTo(high) <= 0)

               System.out.println(lasts[i] + ", " + firsts[i] + ": " + emails[i]);

           else if(func == 2 &&

                   firsts[i].equals(fTarget) && lasts[i].equals(lTarget)){

               System.out.println(lasts[i] + ", " + firsts[i] + ": " + emails[i]);

           }

          

       }

   }

}

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