Question Solved1 Answer Java script public class Utils public static int[] StringToArrayInt(String inputString) { return output IntArray: import org.junit. Test; import static org.junit. Assert.*; // class public class My Test { @Test // method public void testOne() { int returnedArray[] = {}; int answer IntegerTest1[] int answer IntegerTest2[] = {}; {}; = // Test 1 Input and Desired Output System.out.println("Subtest 1: input string is 1 2 3 4"); String myStringTest1 = new String("1 2 3 4"); answer IntegerTest1 = new int[]{1, 2, 3, 4); // desired returned int array. returnedArray = Utils.StringToArrayInt (myStringTest1); // Check that returned array is equal to the model. assertArrayEquals(returnedArray, answer IntegerTest1); // Test 2 Input and Desired Output System.out.println("Subtest 2: input string is 20 30 40 50 60 70 80"); String myStringTest2 = new String("20 30 40 50 60 70 80"); answer IntegerTest2 = new int[]{20, 30, 40, 50, 60, 70, 80}; // desired returned int array. returnedArray = Utils.StringToArrayInt(myStringTest2); 1/ Check that returned array is equal to the model. assertArray Equals(returnedArray, answer IntegerTest2); // //assertArrayEquals(expected, array); } // end method } // end class A String will be passed to your method by VPL's internal tester. The String contains a series of whole numbers, separated by spaces. Your method is expected to return an array of integers. These integers should be the same, and in the same order, as the numbers in the String. (download the Unit test file) One test will send String("1 2 3 4") to your method. It will expect int[]{1,2,3,4} back (you can see that in the Unit test file).

ZW0HJM The Asker · Computer Science

Java script

Transcribed Image Text: public class Utils public static int[] StringToArrayInt(String inputString) { return output IntArray: import org.junit. Test; import static org.junit. Assert.*; // class public class My Test { @Test // method public void testOne() { int returnedArray[] = {}; int answer IntegerTest1[] int answer IntegerTest2[] = {}; {}; = // Test 1 Input and Desired Output System.out.println("Subtest 1: input string is 1 2 3 4"); String myStringTest1 = new String("1 2 3 4"); answer IntegerTest1 = new int[]{1, 2, 3, 4); // desired returned int array. returnedArray = Utils.StringToArrayInt (myStringTest1); // Check that returned array is equal to the model. assertArrayEquals(returnedArray, answer IntegerTest1); // Test 2 Input and Desired Output System.out.println("Subtest 2: input string is 20 30 40 50 60 70 80"); String myStringTest2 = new String("20 30 40 50 60 70 80"); answer IntegerTest2 = new int[]{20, 30, 40, 50, 60, 70, 80}; // desired returned int array. returnedArray = Utils.StringToArrayInt(myStringTest2); 1/ Check that returned array is equal to the model. assertArray Equals(returnedArray, answer IntegerTest2); // //assertArrayEquals(expected, array); } // end method } // end class A String will be passed to your method by VPL's internal tester. The String contains a series of whole numbers, separated by spaces. Your method is expected to return an array of integers. These integers should be the same, and in the same order, as the numbers in the String. (download the Unit test file) One test will send String("1 2 3 4") to your method. It will expect int[]{1,2,3,4} back (you can see that in the Unit test file).
More
Transcribed Image Text: public class Utils public static int[] StringToArrayInt(String inputString) { return output IntArray: import org.junit. Test; import static org.junit. Assert.*; // class public class My Test { @Test // method public void testOne() { int returnedArray[] = {}; int answer IntegerTest1[] int answer IntegerTest2[] = {}; {}; = // Test 1 Input and Desired Output System.out.println("Subtest 1: input string is 1 2 3 4"); String myStringTest1 = new String("1 2 3 4"); answer IntegerTest1 = new int[]{1, 2, 3, 4); // desired returned int array. returnedArray = Utils.StringToArrayInt (myStringTest1); // Check that returned array is equal to the model. assertArrayEquals(returnedArray, answer IntegerTest1); // Test 2 Input and Desired Output System.out.println("Subtest 2: input string is 20 30 40 50 60 70 80"); String myStringTest2 = new String("20 30 40 50 60 70 80"); answer IntegerTest2 = new int[]{20, 30, 40, 50, 60, 70, 80}; // desired returned int array. returnedArray = Utils.StringToArrayInt(myStringTest2); 1/ Check that returned array is equal to the model. assertArray Equals(returnedArray, answer IntegerTest2); // //assertArrayEquals(expected, array); } // end method } // end class A String will be passed to your method by VPL's internal tester. The String contains a series of whole numbers, separated by spaces. Your method is expected to return an array of integers. These integers should be the same, and in the same order, as the numbers in the String. (download the Unit test file) One test will send String("1 2 3 4") to your method. It will expect int[]{1,2,3,4} back (you can see that in the Unit test file).
See Answer
Add Answer +20 Points
Community Answer
L3URS5 The First Answerer
See all the answers with 1 Unlock
Get 4 Free Unlocks by registration

General GuidanceThe answer provided below has been developed in a clear step by step manner.Step: 1CODE WITH EXPLANATION:// declaring stringToIntegerArray functionfunction stringToIntegerArray(str) {t// declaring array of integer which will keep the integer value of each string charactertint_arr = []t// traversing each character of the stringtfor(let i = 0; i < str.length; ++i) {tt// if integer value of the string is an integer value then pushing that element to int_arrtt// This will eliminate the spaces in the stringttif(Number.isInteger(parseInt(str[i]))) {tttint_arr.push(parseInt(str[i]))ttt}t}t// returning the int_arrtreturn int_arr}// declaring the string, you can take input as wellstr = "1 2 3 4"// calling the stringToIntegerArray function and passing string str as arguement and storing the returned result in an arrayint_arr = stringToIntegerArray(str)// printing the result returned from stringToIntegerArray function on the consoleconsole.log(int_arr)CODE + OUTPUT IMAGE:Explanation:Please refer to solution in this step.Answer:.lcWjel{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;font-size:0.75rem;box-sizing:border-box;}/*!sc*/ data-styled.g366[id="sc-mwpquf-0"]{content:"lcWjel,"}/*!sc*/ .loOCZZ{margin:0;font-family:"Aspira Webfont","Helvetica","Arial",sans-serif;}/*!sc*/ .loOCZZ .align-left{text-align:left;}/*!sc*/ .loOCZZ .align-center{text-align:center;}/*!sc*/ .loOCZZ .align-right{text-align:right;}/*!sc*/ data-styled.g367[id="sc-mwpquf-1"]{content:"loOCZZ,"}/*!sc*/ .cpESDm .DraftEditor-editorContainer,.cpESDm .DraftEditor-root,.cpESDm .public-DraftEditor-content{height:inherit;text-align:initial;}/*!sc*/ .cpESDm .public-DraftEditor-content[contenteditable='true']{-webkit-user-modify:read-write-plaintext-only;}/*!sc*/ .cpESDm .DraftEditor-root{position:relative;}/*!sc*/ .cpESDm .DraftEditor-editorContainer{background-color:rgba(255,255,255,0);border-left:0.1px solid transparent;position:relative;z-index:1;}/*!sc*/ .cpESDm .public-DraftEditor-block{position:relative;}/*!sc*/ .cpESDm .DraftEditor-alignLeft .public-DraftStyleDefault-block{text-align:left;}/*!sc*/ .cpESDm .DraftEditor-alignLeft .public-DraftEditorPlaceholder-root{left:0;text-align:left;}/*!sc*/ .cpESDm .DraftEditor-alignCenter .public-DraftStyleDefault-block{text-align:center;}/*!sc*/ .cpESDm .DraftEditor-alignCenter .public-DraftEditorPlaceholder-root{margin:0 auto;text-align:center;width:100%;}/*!sc*/ .cpESDm .DraftEditor-alignRight .public-DraftStyleDefault-block{text-align:right;}/*!sc*/ .cpESDm .DraftEditor-alignRight .public-DraftEditorPlaceholder-root{right:0;text-align:right;}/*!sc*/ .cpESDm .public-DraftEditorPlaceholder-root{color:#9197a3;position:absolute;width:100%;z-index:1;}/*!sc*/ .cpESDm .public-DraftEditorPlaceholder-hasFocus{color:#bdc1c9;}/*!sc*/ .cpESDm .DraftEditorPlaceholder-hidden{display:none;}/*!sc*/ .cpESDm .public-DraftStyleDefault-block{position:relative;white-space:pre-wrap;}/*!sc*/ .cpESDm .public-DraftStyleDefault-ltr{direction:ltr;text-align:left;}/*!sc*/ .cpESDm .public-DraftStyleDefault-rtl{direction:rtl;text-align:right;}/*!sc*/ .cpESDm .public-DraftStyleDefault-listLTR{direction:ltr;}/*!sc*/ .cpESDm .public-DraftStyleDefault-listRTL{direction:rtl;}/*!sc*/ .cpESDm .public-DraftStyleDefault-ol,.cpESDm .public-DraftStyleDefault-ul{margin:16px 0;padding:0;}/*!sc*/ .cpESDm .public-DraftStyleDefault-depth0.public-DraftStyleDefault-listLTR{margin-left:1.5em;}/*!sc*/ .cpESDm .public-DraftStyleDefault-depth0.public-DraftStyleDefault-listRTL{margin-right:1.5em;}/*!sc*/ .cpESDm .public-DraftStyleDefault-depth1.public-DraftStyleDefault-listLTR{margin-left:3em;}/*!sc*/ .cpESDm .public-DraftStyleDefault-depth1.public-DraftStyleDefault-listRTL{margin-right:3em;}/*!sc*/ .cpESDm .publi ... See the full answer