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

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 remov

Post by answerhappygod »

Implement The Method Below That Takes A String Code Str Code As Input Argument And Returns String After Remov 1
Implement The Method Below That Takes A String Code Str Code As Input Argument And Returns String After Remov 1 (346.42 KiB) Viewed 38 times
JUNIT TEST:
@Test
public void test_01_removeConsecutiveDuplicates() {
final String str= "ccccvvvvvvaaaaaabbbcaaaa";
String cleanstr = StringUtility.removeConsecutiveDuplicates(str);
String expect = "cvabca" ;
String str1 = String.format("\nTest removeConsecutiveDuplicates fail for %s. Returned ( %s ), but correct is ( %s )\n", str,cleanstr, expect );
assertTrue(str1, expect.equals(cleanstr));
}
@Test
public void test_02_removeConsecutiveDuplicates() {
final String str= "ECCCCCSSSSSLLLLLLLAAAAAAB";
String cleanstr = StringUtility.removeConsecutiveDuplicates(str);
String expect = "ECSLAB" ;
String str1 = String.format("\nTest removeConsecutiveDuplicates fail for %s. Returned ( %s ), but correct is ( %s )\n", str,cleanstr, expect );
assertTrue(str1, expect.equals(cleanstr));
}
@Test
public void test_03_removeConsecutiveDuplicates() {
final String str= "YYYORKKKKKKKTTOOORONTO";
String cleanstr = StringUtility.removeConsecutiveDuplicates(str);
String expect = "YORKTORONTO" ;
String str1 = String.format("\nTest removeConsecutiveDuplicates fail for %s. Returned ( %s ), but correct is ( %s )\n", str,cleanstr, expect );
assertTrue(str1, expect.equals(cleanstr));
}
In Java,
Please do the implementation below the where that wrote "Your implementation" and write the same class as the pictures do not change anything thanks and there's information below class about what you should write thanks and that's the Junit test project all of the task should be pass thanks and please provide your screen shot of your code that all of the task are passed with the my junit test that i provided for you
/** * Implement the method below that takes a String <code>str</code> 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 <strong> important</strong>, so the strings "ECSLAB" and "CELABS" * are different. * <p> * <strong> You can assume that the input String is not null and contains at * least 2 two characters.</strong> * </p> * <p> * For example: * </p> * * <pre> * if str = "EECCCCCSSSLLLLLAB" then return "ECSLAB" * * * * </pre> * 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. */
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply