/** * Implement the method below that takes a String str as input * argument and returns string after removing all conse

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

/** * Implement the method below that takes a String str as input * argument and returns string after removing all conse

Post by answerhappygod »

Implement The Method Below That Takes A String Str As Input Argument And Returns String After Removing All Conse 1
Implement The Method Below That Takes A String Str As Input Argument And Returns String After Removing All Conse 1 (346.42 KiB) Viewed 27 times
In Java,
Please do the implementation below the where that wrote "Yourimplementation" and write the same class as the pictures donot change anything thanks and there's information below classabout what you should write thanks and that's the Junit testproject all of the task should be pass thanks and please provideyour screen shot of your code that all of the task are passed withthe my junit test that i provided for you
/** * Implement the method below that takes a String str as input * argument and returns string after removing all consecutive duplicates * characters from the input string. The order of characters in the returned * string is important, so the strings "ECSLAB" and "CELABS" * are different. * * You can assume that the input String is not null and contains at * least 2 two characters. * * * For example: * * * * if str = "EECCCCCSSSLLLLLAB" then return "ECSLAB" * * * * * if str = "0001110001001" then return "010101" if str = "cvvvvaaabcca" then return "cvabca" if str "LabTtttEeeeSsssT" then return "LabTtEeSsT" * @param str : input String * @return string after removing all consecutive duplicates * characters from the input string. */ public static String removeConsecutive Duplicates (String str) { /* Your implementation of this method starts here. * Recall that : * 1. No System.out.println statements should appear here. Instead, you need to return the result. * * 2. No Scanner operations should appear here (e.g., input.nextInt()). * Instead, refer to the input parameters of this method. */
aTest public void test_00_removeDuplicatesChar() { } } final String str= "EECCCCCSSSLLLLLAB"; char [] cleanstr = char [] expect = "ECSLAB".toCharArray(); Arrays.sort (expect); Arrays.sort(cleanstr); String str1 = String.format("\nTest removeDuplicates Char fail for %s. Returned ( %s )," + " but correct is ( %s\n", str,StringUtility.removeDuplicatesChar(str), "ECSLAB" ); assertTrue (str1, Arrays.equals(cleanstr, expect)); aTest public void test_01_removeDuplicates Char() { StringUtility.removeDuplicatesChar (str).toCharArray(); } final String str= "0001110001001"; char [] cleanstr = StringUtility.removeDuplicatesChar(str).toCharArray(); char [] expect = "01".toCharArray(); Arrays.sort (expect); Arrays.sort(cleanstr); String str1 = String.format("\nTest removeDuplicatesChar fail for %s. Returned ( %s )," + " but correct is ( %s\n", str, StringUtility.removeDuplicatesChar(str), "01" ); assertTrue (str1, Arrays.equals(cleanstr, expect )); aTest public void test_02_removeDuplicatesChar() { final String str= "AAAABBBCCC"; char [] cleanstr = StringUtility.removeDuplicates Char (str).toCharArray(); char [] expect = "CBA".toCharArray(); Arrays.sort (expect); Arrays.sort(cleanstr); String str1 = String.format("\nTest removeDuplicatesChar fail for %s. Returned ( %s ), but correct is ( %s )\n", str,cleanstr, expect ); assertTrue (str1, Arrays.equals(cleanstr, expect));
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply