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.

Students were asked to answer a question at schools and to say what is most important for them to succeed. One which response stood out from the rest was practice. People who commonly are successful do not become successful by being born. They work hard and perseverance their lives to succeeding. This is how you can obtain your goals. Below some question and answer examples that you would probably make use of to enriches your knowledge and gain insight that will assist you to continue your school studies.

Question:

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.

Answer:

The program is an illustration of methods

READ MORE  When must the sanitizing step occur when cleaning and sanitizing in a three compartment sink

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));

       for(double num : newList) {

 }

 //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));

     }

     for(double num : newList) {

         System.out.print(num + ” “);

Read more about methods at:

From the answer and question examples above, hopefully, they could simply help the student resolve the question they had been looking for and notice of all the pieces declared in the answer above. Then would certainly have some sharing in a group discussion and also study with the classmate regarding the topic, so another student also has some enlightenment and still keeps up the school learning.

Leave a Reply

Your email address will not be published.