1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kicyunya [14]
3 years ago
15

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.
Computers and Technology
1 answer:
Troyanec [42]3 years ago
4 0

The program is an illustration of methods

<h3>What are methods</h3>

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

<h3>The actual program</h3>

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:

brainly.com/question/15683939

You might be interested in
CHALLENGE
Lorico [155]

Answer:

Following are the program to this question:

#include <stdio.h>//using the header file

int main()//main method

{

int y;//defining integer variable y

printf("Enter year value:");//print message

scanf("%d", &y);//use input method for input year value

if (y>= 2101)//defining if block that checks year greater then 2101

   printf("Distant future");//print message

else if (y>= 2001)//defining else if block that checks year greater then 2001

   printf("21st century"); //print message

else if (y>= 1901)//defining else if block that checks year greater then 1901

   printf("20th century");//print message

else  //defining else block

   printf("Long ago");//print message

   return 0;

}

Output:

Enter year value:1998

20th century

Explanation:

In the given C language code, inside the main method, an integer variable "y" is defined, which allows the user to input the year value, and use the multiple conditions to check the given value and print message when the condition is matched.  

  • Inside the "if" condition block, it checks the "y" variable value is greater and equal to 2101. so, it will print "Distant future", otherwise go to the next condition.
  • In this, if "y" value is greater than equal to "2001", it will print the message "21st century", otherwise go to the next condition.  
  • In this, If the value of "y" is greater than equal to "1901", it will print the message "20th century", and if all the above condition is not true, then it will go to the else block, and it will print "Long ago" as the message.
6 0
3 years ago
"Dean wants a quick way to look up staff members by their Staff ID. In cell Q3, nest the existing VLOOKUP function in an IFERROR
Feliz [49]

Answer:

ierror(VLOOKUP(Q2,CBFStaff[[Staff ID]:[Name]],2,FALSE), "Invalid Staff ID")

Explanation:

Let me try as much as I can to explain the concept or idea of iferror in vlookup.

iferror have a typically function and result like an if else statement, its syntax is IFERROR(value,value _ if _ error), this simply means that if the the error is equal to value, value is returned if not, the next argument is returned.

Having said that, feom the question we are given,

let's substitute the value with vlookup function and add an else argument, it will look exactly this way;

IFERROR(VLOOKUP(),"Invalid Staff ID")// now this will set the message if vlookup cannot find the.

On the other hand using the values given, we will have;

ierror(VLOOKUP(Q2,CBFStaff[[Staff ID]:[Name]],2,FALSE), "Invalid Staff ID")

4 0
4 years ago
Write a recipe that stores the sum of the numbers 12 and 33 in a variable named sum. Have your recipe display the value stored i
VARVARA [1.3K]

Answer:

#include<iostream>

using namespace std;

int main(){

   int sum = 12+33;

   cout<<"The sum is: "<<sum<<endl;

}

Explanation:

First include the library iostream in c++ program for input/output.

Then, create the main function and declare the variable sum as integer type and store the sum of two given values.

After that, display the result store in the sum variable on the screen by using the instruction cout.

8 0
3 years ago
Historically, development of a new technology often:
andrew-mc [135]

Answer:

2. Leads to increases in productivity only once firms learn how to use it.

Explanation:

Technology is an all new or improved way of doing things to enhance effectiveness and efficiency that will lead to increase output. But the new technologies can not improve a business output if they don't grow with the trend of new technologies by updating their knowledge regularly

7 0
3 years ago
Read 2 more answers
Drag each label to the correct location on the image. Identify parts of the table. Primary key, field, record, table.
Oksana_A [137]

Answer:

What Is It about

Explanation:

Reply ill help you Im a teacher

7 0
4 years ago
Read 2 more answers
Other questions:
  • Which education level has the highest return on investment (ROI)?
    14·1 answer
  • Refer to the exhibit, a technician applies the configuration in the exhibit to an unconfigured router. To verify the configurati
    13·1 answer
  • Create a script that will find the sum of the all multiples of 3 between 1 and 1000 by using For Loop. (Pseudo Code required) 3.
    7·1 answer
  • Explicit knowledge can be documented and codified, whereas tacit knowledge encompasses insights, judgment, creative processes, a
    9·1 answer
  • Versiones del Moodle
    10·1 answer
  • Adios brainly, you were sh.t sometimes, but you had your moments, wont be posting that much take my points away i d c
    6·2 answers
  • Why does 5G mmWave require more cells to achieve a better signal?
    10·1 answer
  • 2. Cryptography relies on open standards - a protocol or standard that is publicly available. Why are open standards necessary
    5·1 answer
  • Submit a report outlining the steps you will take to obtain digital evidence. In your report you must include the legal requirem
    11·1 answer
  • What are some of the key system-oriented trends that have fostered is-supported decision making to a new level?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!