From 824aad5753f338537c1ccd6d1d909fc04855d0d1 Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Thu, 15 Jun 2023 11:41:34 -0700 Subject: [PATCH 01/12] first commit with two updated files --- src/main/java/StringManipulation.java | 143 +++++++++++++++-- src/test/java/StringManipulationTest.java | 187 ++++++++++++++++++---- 2 files changed, 292 insertions(+), 38 deletions(-) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index 4deb6f1..d5e75c9 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,33 +1,154 @@ -public class StringManipulation implements StringManipulationInterface { +import java.util.ArrayList; +public class StringManipulation implements StringManipulationInterface { + + private String string; + private int count; + @Override public String getString() { - return null; + return string; } @Override public void setString(String string) { + this.string = string; } @Override public int count() { - return 0; + // initialize word count to 0 + count = 0; + + // if statement to check if string is null or empty + if (string == null || string.length() == 0) { + return count; + } + + // split the string into a string array, delimiting by one or more spaces + String[] wordArray = this.string.split("\\s+"); + + count = wordArray.length; + + return count; } @Override - public String removeNthCharacter(int n, boolean maintainSpacing) { - return null; + public String removeNthCharacter(int n, boolean maintainSpacing) { + if (n > string.length()) { + throw new IndexOutOfBoundsException(); + } else if (n <= 0) { + throw new IllegalArgumentException(); + } + + // initialize an ArrayList of Characters + ArrayList charArray = new ArrayList(); + + // iterate through string and insert each Character in the ArrayList + for (int i = 0; i < string.length();i ++) { + charArray.add(string.charAt(i)); + } + + // determine the highest Nth index less than or equal to the length of this.string + int limit = string.length() / n; + + // initialize an int array to hold all the indexes to replace + int[] indexesToReplace = new int[limit]; + + // assign each Nth index to an element in the int array + for (int i = 1, j = 0; i <= limit; i++, j++) { + indexesToReplace[j] = n * i; + } + + //System.out.println("indexes to replace: " + Arrays.toString(indexesToReplace)); + + // iterate through the ArrayList and replace the Character with space or delete + for (int i = indexesToReplace.length - 1; i >= 0; i--) { + int index = indexesToReplace[i] - 1; + + if (maintainSpacing == true) { + charArray.set(index, ' '); + } + + if (maintainSpacing == false) { + charArray.remove(index); + } + } + + // build the string from the ArrayList and return to main + StringBuilder stringBuilder = new StringBuilder(); + for (char c : charArray) { + stringBuilder.append(c); + } + + return stringBuilder.toString(); } @Override - public String[] getSubStrings(int startWord, int endWord) { - return null; + public String[] getSubStrings(int startWord, int endWord){ + // exception: If either "startWord" or "endWord" are invalid + if (startWord <= 0 || endWord <= 0 || startWord > endWord) { + throw new IllegalArgumentException(); + } + + // exception: If the string has less than "endWord" words in it + if (count() < endWord) { + throw new IndexOutOfBoundsException(); + } + + // split the words into a String array, delimited by one or more spaces + String[] arr = this.string.split("\\s+"); + + // intialize the return array with size of the number of words to keep + String[] finalArray = new String[endWord - startWord + 1]; + + // iterate through the array of all words, if the index falls inside the + // range passed in, then put that word in the new array + for (int i = 0, j = 0; i <= arr.length; i++) { + if (i >= startWord && i <= endWord) { + finalArray[j] = arr[i - 1]; + j++; + } + } + + return finalArray; } @Override - public String restoreString(int[] indices) { - return null; + public String restoreString(int[] indices){ + // exception: if not s.length == indices.length == n + if (string.length() != indices.length) { + throw new IllegalArgumentException(); + } + + // exception: if indices[i] < 0 or indices[i] > string length + for (int i = 0 ; i < indices.length; i++) { + if (indices[i] < 0 || indices[i] >= string.length()) { + throw new IndexOutOfBoundsException(); + } + } + + // initialize an ArrayList for the final string to be returned + ArrayList finalWord = new ArrayList<>(); + + // fill the ArrayList with characters from the original string + for (char c : string.toCharArray()) { + finalWord.add(c); + } + + // iterate through both the indices parameter and the string characters + // to load the final array with shuffled characters + for (int i = 0; i < string.length(); i++) { + finalWord.set(indices[i], string.charAt(i)); + } + + // build the string from the ArrayList and return to main + StringBuilder stringBuilder = new StringBuilder(); + for (char c : finalWord) { + stringBuilder.append(c); + } + + return stringBuilder.toString(); } - - } + diff --git a/src/test/java/StringManipulationTest.java b/src/test/java/StringManipulationTest.java index 6692c2c..11fb33c 100644 --- a/src/test/java/StringManipulationTest.java +++ b/src/test/java/StringManipulationTest.java @@ -1,8 +1,5 @@ -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - - +import org.junit.jupiter.api.*; +import static org.junit.Assert.assertThrows; import static org.junit.jupiter.api.Assertions.*; public class StringManipulationTest { @@ -26,19 +23,33 @@ public void testCount1() { assertEquals(4, length); } + // This test checks if an empty string will have a word count of 0. + // The method should return a count of 0 for a string with 0 words. @Test public void testCount2() { - fail("Not yet implemented"); + manipulatedstring.setString(""); + int length = manipulatedstring.count(); + assertEquals(0, length); } + // This test checks whether the method will return 5 for a string with 5 words + // despite a series of spaces at the end of the string. The method should disregard + // all the spaces in string when counting the number of words. @Test public void testCount3() { - fail("Not yet implemented"); + manipulatedstring.setString("this sentence has 5 words. "); + int length = manipulatedstring.count(); + assertEquals(5, length); } + // This test checks whether the method will return 3 for a string with 3 words + // despite the string having a series of spaces in between words. The method should + // disregard the number of spaces between words even if they are more than one space. @Test public void testCount4() { - fail("Not yet implemented"); + manipulatedstring.setString("1 2 3 "); + int length = manipulatedstring.count(); + assertEquals(3, length); } @Test @@ -53,29 +64,70 @@ public void testRemoveNthCharacter2() { assertEquals("I' b tt r ut s0 e 16 ts in th s tr n6 r gh ?", manipulatedstring.removeNthCharacter(3, true)); } + // This will test whether the method will correctly remove the characters + // in a string with 12 characters by a factor of 2. With a factor of 2 and a + // string of length 12, the characters at position 2,4,6,8,10,12 will be removed + // and since the maintainSpacing parameter is false, then the characters at those + // positions will be deleted. @Test public void testRemoveNthCharacter3() { - fail("Not yet implemented"); + manipulatedstring.setString("hello world!"); + assertEquals("hlowrd", manipulatedstring.removeNthCharacter(2, false)); } - + + // This will test whether the method will correctly remove the characters + // in a string with 12 characters by a factor of 3. With a factor of 3 and a + // string of length 12, the characters at position 3,6,9,12 will be removed + // and since the maintainSpacing parameter is true, then the characters at those + // positions will be replaced with a space character. + // + // The character in the last position will be replaced with a space which will + // maintain the original string length of 12 @Test public void testRemoveNthCharacter4() { - fail("Not yet implemented"); + manipulatedstring.setString("hello world!"); + assertEquals("he lo wo ld ", manipulatedstring.removeNthCharacter(3, true)); } + // This will test the maintainSpacing of the method. The given string has a total of 5 + // spaces that are originally in the string. With false passed in for maintainSpacing, + // the output string should retain the 5 spaces and remove the characters at positions 3n. @Test public void testRemoveNthCharacter5() { - fail("Not yet implemented"); + manipulatedstring.setString("0 3 6 9"); + assertEquals("0 ", manipulatedstring.removeNthCharacter(3, false)); } - + + // This will test that the method will throw an IndexOutOfBoundsException() + // if n is greater than the string length, it is not possible to remove characters + // by a factor that is greater than the length of the string. + // + // In this test case, the string has a total of 19 characters, and the nth parameter + // that is passed in is 20, therefore, there is no 20th character to remove, and + // the method will catch this 20th index as out of bounds for the string. @Test public void testRemoveNthCharacter6() { - fail("Not yet implemented"); + manipulatedstring.setString("index out of bounds"); + + assertThrows(IndexOutOfBoundsException.class, () -> { + manipulatedstring.removeNthCharacter(20, true); + }); } + // This will test that the method will throw an IllegalArgumentException() + // if n <= 0 then that is not a valid factor to remove characters by. + + // In this test case, the string has a total of 26 characters, and the nth parameter + // that is passed in is 0, therefore, the parameter is invalid because 0n is always 0, + // which is not a valid factor, as the method calls for the first index position + // of the string as position 1. The method will catch this and throw an error. @Test public void testRemoveNthCharacter7() { - fail("Not yet implemented"); + manipulatedstring.setString("illegal argument exception"); + + assertThrows(IllegalArgumentException.class, () -> { + manipulatedstring.removeNthCharacter(0, false); + }); } @Test @@ -87,25 +139,69 @@ public void testGeSubStrings1() { assertEquals(sStings[1], "string"); } + // This test will grab the second through the fifth word in the string, + // despite the series of spaces in between the words. The number of spaces in + // between words should not affect the method. @Test public void testGeSubStrings2() { - fail("Not yet implemented"); + manipulatedstring.setString("test string that has many spaces"); + String [] sStings = manipulatedstring.getSubStrings(2, 5); + + assertEquals(sStings[0], "string"); + assertEquals(sStings[1], "that"); + assertEquals(sStings[2], "has"); + assertEquals(sStings[3], "many"); } + + // This test will test grab only the first word in the string, by taking + // the startWord as the first word and taking the endWord as the last word. + // The method should allow only one word to be plucked from the string by + // taking both the startWord and endWord parameter as the same number. + // This test also checks whether the series of spaces in between the two words + // will affect the output. A series of spaces between words should not have an affect. @Test public void testGeSubStrings3() { - fail("Not yet implemented"); + manipulatedstring.setString("test string"); + String [] sStings = manipulatedstring.getSubStrings(1, 1); + + assertEquals(sStings[0], "test"); } + + // This test will grab only the last word in the string of many words, all with + // a series of spaces in between the words. The startWord and endWord parameters + // are the same number which is the number for the last word in the string. @Test public void testGeSubStrings4() { - fail("Not yet implemented"); + manipulatedstring.setString("another test of this method"); + String [] sStings = manipulatedstring.getSubStrings(5, 5); + + assertEquals(sStings[0], "method"); } + + // This will test the method if it correctly returns an IllegalArgumentException(). + // If the startWord parameter is <= 0 or if startWord > endWord, + // then the method will through an IllegalArgumentException. This test will catch + // both of these illegal cases and throw the appropriate exception. @Test public void testGeSubStrings5() { - fail("Not yet implemented"); + manipulatedstring.setString("illegal argument exception"); + + assertThrows(IllegalArgumentException.class, () -> { + manipulatedstring.getSubStrings(0, -5); + }); } + + // This will test the method if it correctly returns an IndexOutOfBoundsException(). + // If the parameter passed in for endWord is greater than the count of words in the + // string then the method should throw an IndexOutOfBounds exception. In this + // test, the endWord is 6 for only a string with a word count of 5, throwing an error. @Test public void testGeSubStrings6() { - fail("Not yet implemented"); + manipulatedstring.setString("index out of bounds exception"); + + assertThrows(IndexOutOfBoundsException.class, () -> { + manipulatedstring.getSubStrings(2, 6); + }); } @Test @@ -118,32 +214,69 @@ public void testRestoreString1() assertEquals(restoreString, "rat"); } + // This will test the method if it will swap the two words in the string. + // With the space seperating the word staying in it's place, the test + // will take each character from each side of the space and swap then for the + // character on the other side of the space and output a swapped string of two words. @Test public void testRestoreString2() { - fail("Not yet implemented"); + manipulatedstring.setString("four five"); + int [] array; + array=new int[]{5,6,7,8,4,0,1,2,3}; + String restoreString = manipulatedstring.restoreString(array); + assertEquals(restoreString, "five four"); } + // This will test the method to move all spaces in between the characters into + // one large space after the first character. @Test public void testRestoreString3() { - fail("Not yet implemented"); + manipulatedstring.setString("a b c d e f g"); + int [] array; + array=new int[]{0,1,7,2,8,3,9,4,10,5,11,6,12}; + String restoreString = manipulatedstring.restoreString(array); + assertEquals(restoreString, "a bcdefg"); } + // This will test if the method will throw an IllegalArgumentException(). + // The method should accept an int array of equal size to the string that is + // being manipulated. In this test case, the string has 24 characters, and the + // int array that is passed in only has 6 elements. Therefore, this is an invalid + // size of int array, throwing an illegal argument exception. @Test public void testRestoreString4() { - fail("Not yet implemented"); - + manipulatedstring.setString("illegalargumentexception"); + int [] array; + array=new int[]{5,4,3,2,1,0}; + + assertThrows(IllegalArgumentException.class, () -> { + manipulatedstring.restoreString(array); + }); } + // This will test if the method will throw an IndexOutOfBoundsException(). + // The method should accept an int array that is comprised of elements that + // correspond to the elements of characters in the string. If any of the elements + // in the int array is less than 0 or greater than or equal to the string length, + // then that is an invalid element number for a string. In this test case, + // -1 and 5 are elements in the int array. There is no -1 character element in any + // string and there is no character element of 5 for the given string which has + // character elements 0 through 4. These parameters will throw an exception. @Test public void testRestoreString5() { - fail("Not yet implemented"); - + manipulatedstring.setString("ioobe"); + int [] array; + array=new int[]{0,-1,2,5,4}; + + assertThrows(IndexOutOfBoundsException.class, () -> { + manipulatedstring.restoreString(array); + }); } - } + From 8ed1695f0500461d23558b4678cb7733dc2dd046 Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Thu, 15 Jun 2023 12:36:02 -0700 Subject: [PATCH 02/12] removed import statements --- src/main/java/StringManipulation.java | 2 -- src/test/java/StringManipulationTest.java | 4 ---- 2 files changed, 6 deletions(-) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index d5e75c9..f84dd4b 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,5 +1,3 @@ -import java.util.ArrayList; - public class StringManipulation implements StringManipulationInterface { private String string; diff --git a/src/test/java/StringManipulationTest.java b/src/test/java/StringManipulationTest.java index 11fb33c..5dd9230 100644 --- a/src/test/java/StringManipulationTest.java +++ b/src/test/java/StringManipulationTest.java @@ -1,7 +1,3 @@ -import org.junit.jupiter.api.*; -import static org.junit.Assert.assertThrows; -import static org.junit.jupiter.api.Assertions.*; - public class StringManipulationTest { private StringManipulationInterface manipulatedstring; From 62b0e2743666ac19f8045148d00d75bf4f30488c Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Thu, 15 Jun 2023 15:45:54 -0700 Subject: [PATCH 03/12] added import statement --- src/main/java/StringManipulation.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index f84dd4b..2eaefbe 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,3 +1,4 @@ + public class StringManipulation implements StringManipulationInterface { private String string; From a8cff80a062b1be03c8cb700a2b3e47e4ad1bc8c Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Thu, 15 Jun 2023 15:57:11 -0700 Subject: [PATCH 04/12] added import statements to test file --- src/main/java/StringManipulation.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index 2eaefbe..d5e75c9 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; public class StringManipulation implements StringManipulationInterface { From f08a6f662c14a61048ac1e9c576438fd5a9cb77e Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Thu, 15 Jun 2023 16:14:44 -0700 Subject: [PATCH 05/12] changed some code --- src/test/java/StringManipulationTest.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/java/StringManipulationTest.java b/src/test/java/StringManipulationTest.java index 5dd9230..11fb33c 100644 --- a/src/test/java/StringManipulationTest.java +++ b/src/test/java/StringManipulationTest.java @@ -1,3 +1,7 @@ +import org.junit.jupiter.api.*; +import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.*; + public class StringManipulationTest { private StringManipulationInterface manipulatedstring; From 061c1ba58e749a2d1bf933b8314d7ef321dfb2e1 Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Thu, 15 Jun 2023 16:39:58 -0700 Subject: [PATCH 06/12] more import statement changes --- src/test/java/StringManipulationTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/test/java/StringManipulationTest.java b/src/test/java/StringManipulationTest.java index 11fb33c..077cbdd 100644 --- a/src/test/java/StringManipulationTest.java +++ b/src/test/java/StringManipulationTest.java @@ -1,7 +1,11 @@ -import org.junit.jupiter.api.*; -import static org.junit.Assert.assertThrows; +//import org.junit.jupiter.api.*; +//import static org.junit.Assert.assertThrows; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; + public class StringManipulationTest { private StringManipulationInterface manipulatedstring; From be0aa0d18b32410e371a9a27c4df9d08855682ab Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Fri, 16 Jun 2023 17:57:27 -0700 Subject: [PATCH 07/12] refactored test --- src/main/java/StringManipulation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index d5e75c9..1fca85a 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,4 +1,4 @@ -import java.util.ArrayList; +//import java.util.ArrayList; public class StringManipulation implements StringManipulationInterface { From 9704ca075f70a1bbcbc3f29cc724696bc16fbe03 Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Fri, 16 Jun 2023 18:20:20 -0700 Subject: [PATCH 08/12] attempt to pass Travis test --- src/test/java/StringManipulationTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/StringManipulationTest.java b/src/test/java/StringManipulationTest.java index 077cbdd..b0a6ec5 100644 --- a/src/test/java/StringManipulationTest.java +++ b/src/test/java/StringManipulationTest.java @@ -232,6 +232,24 @@ public void testRestoreString2() assertEquals(restoreString, "five four"); } + + // This new test is in response to Alvin Bautista's GitHub code review: + // + // Since whitespace characters are a string (substring) then the method + // will take the whitespace and move it to the appropriate index that + // the int array calls for. + // + // Thanks for the comment, Alvin! + @Test + public void testRestoreString6() + { + manipulatedstring.setString("move all spaces to end of string"); + int [] array; + array=new int[]{0,1,2,3,26,4,5,6,27,7,8,9,10,11,12,28,13,14,29,15,16,17,30,18,19,31,20,21,22,23,24,25}; + String restoreString = manipulatedstring.restoreString(array); + assertEquals(restoreString, "moveallspacestoendofstring "); + + } // This will test the method to move all spaces in between the characters into // one large space after the first character. From 3cf01236cefa8e639315e1a8ad80064a9641b71e Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Fri, 16 Jun 2023 18:27:03 -0700 Subject: [PATCH 09/12] import changes --- src/main/java/StringManipulation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index 1fca85a..b9d7856 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,4 +1,4 @@ -//import java.util.ArrayList; +///////import java.util.ArrayList; public class StringManipulation implements StringManipulationInterface { From dc2311cee37a2b5952cc0ff0a754c8521e73e0f1 Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Fri, 16 Jun 2023 18:34:58 -0700 Subject: [PATCH 10/12] fixing Travis issues --- src/main/java/StringManipulation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index b9d7856..d8bcfc6 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,4 +1,4 @@ -///////import java.util.ArrayList; +/////import java.util.ArrayList; public class StringManipulation implements StringManipulationInterface { From d5d61bd87b975824d2606077cc298d3ef053405d Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Fri, 16 Jun 2023 18:39:46 -0700 Subject: [PATCH 11/12] more revisions to pass Travis --- src/main/java/StringManipulation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/StringManipulation.java b/src/main/java/StringManipulation.java index d8bcfc6..d5e75c9 100644 --- a/src/main/java/StringManipulation.java +++ b/src/main/java/StringManipulation.java @@ -1,4 +1,4 @@ -/////import java.util.ArrayList; +import java.util.ArrayList; public class StringManipulation implements StringManipulationInterface { From 56ccfeb3fb13653e9ac9774ba55390dfd7f36876 Mon Sep 17 00:00:00 2001 From: Mark Bonner Date: Fri, 16 Jun 2023 20:23:14 -0700 Subject: [PATCH 12/12] added new test case --- src/test/java/StringManipulationTest.java | 42 +++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/test/java/StringManipulationTest.java b/src/test/java/StringManipulationTest.java index b0a6ec5..86e9629 100644 --- a/src/test/java/StringManipulationTest.java +++ b/src/test/java/StringManipulationTest.java @@ -102,6 +102,48 @@ public void testRemoveNthCharacter5() { assertEquals("0 ", manipulatedstring.removeNthCharacter(3, false)); } + // This new test is in response to Alvin Bautista's GitHub code review: + // + // This test will test 9 different test cases: 1 <= n <= 9 + // + // Thanks for the comment, Alvin! + @Test + public void testRemoveNthCharacter8() { + manipulatedstring.setString("123456789"); + + for (int n = 1; n <= 9; n++) { + switch (n) { + case 1: + assertEquals("", manipulatedstring.removeNthCharacter(n, false)); + break; + case 2: + assertEquals("13579", manipulatedstring.removeNthCharacter(n, false)); + break; + case 3: + assertEquals("124578", manipulatedstring.removeNthCharacter(n, false)); + break; + case 4: + assertEquals("1235679", manipulatedstring.removeNthCharacter(n, false)); + break; + case 5: + assertEquals("12346789", manipulatedstring.removeNthCharacter(n, false)); + break; + case 6: + assertEquals("12345789", manipulatedstring.removeNthCharacter(n, false)); + break; + case 7: + assertEquals("12345689", manipulatedstring.removeNthCharacter(n, false)); + break; + case 8: + assertEquals("12345679", manipulatedstring.removeNthCharacter(n, false)); + break; + case 9: + assertEquals("12345678", manipulatedstring.removeNthCharacter(n, false)); + break; + } + } + } + // This will test that the method will throw an IndexOutOfBoundsException() // if n is greater than the string length, it is not possible to remove characters // by a factor that is greater than the length of the string.