At Westonci.ca, we provide clear, reliable answers to all your questions. Join our vibrant community and get the solutions you need. Ask your questions and receive detailed answers from professionals with extensive experience in various fields. Explore comprehensive solutions to your questions from a wide range of professionals on our user-friendly platform.

CodeHS 7.3.7 JAVA In this exercise, you will create a couple of helper methods for ArrayLists in a class called ArrayListMethods. Create three static methods: print- This method takes an ArrayList as a parameter, and simply prints each value of the ArrayList on a separate line in the console. condense- This method takes an ArrayList as a parameter, and condenses the ArrayList into half the amount of values. While traversing, this method will take the existing value at the index and multiplies the element following to the existing value. For example, if we had an ArrayList that consisted of Doubles [1, 2.5, 2, 3.5], then ArrayListMethods.condense([1, 2.5, 2, 3.5]) would alter the ArrayList to be [2.5, 7]. duplicate- This method takes an ArrayList and duplicates all of the values by adding each value to the end of the ArrayList. For example, ArrayListMethods.duplicate([2.5, 7]) would be [2.5, 7, 2.5, 7]. If done correctly, the methods should work in the ArrayListMethodsTester file.

Sagot :

The program is an illustration of methods

What are methods

Methods are collections of named code statements, that are executed when evoked

The actual program

The program written in Java, where comments are used to explain each line is as follows:

//This defines the print method

   public static void print(ArrayList<Double> myArrayList){

//This iterates through the ArrayList

       for(double num : myArrayList) {

//This prints every element in the list

           System.out.print(num + " ");

       }

       System.out.println();

   }

//This defines the condense method    

   public static void condense(ArrayList<Double> myArrayList){

//This defines a new ArrayList

       ArrayList<Double> newList = new ArrayList<>();

//The following condenses the list

       for(int i = 0; i < myArrayList.size(); i+=2){

           newList.add(myArrayList.get(i) * myArrayList.get(i + 1));

       }

//This prints every element in the list

       for(double num : newList) {

           System.out.print(num + " ");

       }

       System.out.println();

 }

 //Thid defines the duplicate method

 public static void duplicate(ArrayList<Double> myArrayList){

     ArrayList<Double> newList = new ArrayList<>();

//The following duplicates the list

     for(int i = 0; i < myArrayList.size(); i++){

         newList.add(myArrayList.get(i));

         newList.add(myArrayList.get(i));

     }

//This prints every element in the list

     for(double num : newList) {

         System.out.print(num + " ");

     }

 }

Read more about methods at:

https://brainly.com/question/15683939