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

4q132 How do i doing Task1? thanks 4.Java-assignments I-Makefile l-checkstyle-6.

ID: 668653 • Letter: 4

Question

4q132

How do i doing Task1? thanks

4.Java-assignments I-Makefile l-checkstyle-6.5-all.jar Ihamcrest-core-1.3.jar junit-4.12.jar I-Src lArray java lElement.java Ne stedArray.java x--tests I-MyTestRunner.java -- NestedArrayTest. java 1.Makefile is analogous to the Makefile from the previous assignments 2. In this assignment you are provided with a skeleton project that you will fill out. 3.You must not create any extra classes. 4.You may add any extra member methods and fields you wish to any of the classes except HylestRunner 5.All of your file, class, and method names, if specified in this assignment, must have the exact names specified Assignment task: In this assignment we are interested in nested arrays of integers, for example 1, 2, 3, -1, 10], 1, 21, 11, 121 We represent such nested arrays in Java using two classes Element and Array. Do not confuse our Array class with java.util.Array. Note that our Element and Array classes implement the NestedArray interface. Instances of Element represent leaves of our nested array. Instances of Array are arrays of Element and Array classes, observe the recursive definition. For example, 1, 2, 3, -1, -101, 1, 21, -11, 12] is represented by Array (Element (1), Element (2), Element (3), Array (Array (Element (-l) Element (10)), Element (1) Element (2)), Element (-11), Element (12)) You could think of all of this as describing a file hierarchy, where each Element object is a file with a name that is an integer, and each Array object is a directory which can contain files, that is Element objects, and further sub-directories, that is, Array objects. In this way you can think of the above classes as representing a type of tree. You should implement the methods in the following tasks using test driven development (Junit test). You must write your tests in the provided NestedArrayTest class.

Explanation / Answer

task 1 code

import java.util.Arrays;

public class task1 {
     
        public static void main(String args[]){
             
                //String array
                String[] strArray =
                        new String[]{"Java", "String", "Array", "To", "String", "Example"};
             
             
             
                String str1 = Arrays.toString(strArray);             
                //replace starting "[" and ending "]" and ","
                str1 = str1.substring(1, str1.length()-1).replaceAll(",", "");
             
                System.out.println("String 1: " + str1);
             
                String str2 = Arrays.asList(strArray).toString();
                //replace starting "[" and ending "]" and ","
                str2 = str2.substring(1, str2.length()-1).replaceAll(",", "");
                System.out.println("String 2: " + str2);
             
             
                //3. Using StringBuffer.append method
                StringBuffer sbf = new StringBuffer();
             
                if(strArray.length > 0){
                     
                        sbf.append(strArray[0]);
                        for(int i=1; i < strArray.length; i++){
                                sbf.append(" ").append(strArray[i]);
                        }
                     
                }
                System.out.println("String 3: " + sbf.toString());
             
        }
     
}

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