The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Please provide a solution for the document below using Java.Â
Â
Â
1. Create a static method with the following definition
public static double createArray (int size)
The method should create a new empty array of doubles, of size ‘size’ and return a reference to that
array (see sample code) 2. Create an instance method with the following definition:
public void printArray(double inputArray)
The method should print all the element in the array inputArray (see sample code) 3. Create an instance method with the following definition.
public void initArrayLinearAscending(double inputArray)
The method should initialize the array inputArray to values from 1 up to the size of the array. For
example inputArray[0]= 1, inputArray[1] = 2, inputArray[2] = 3, and so on. (see initArray method in
sample code).
4. Create an instance method with the following definition.
public void initArrayLinearDescending (double inputArray)
The method should initialize the array inputArray to values from inputArray.length up to the size of the
array. For example inputArray[0]= 1, inputArray[1] = 2, inputArray[2] = 3, and so on. (see initArray
method in sample code)
5. Create an instance method with the following definition.
public void squareArray (double inputArray)
This method should update each cell in the inputArray to the square of its current value. For example,
inputArray[0] = inputArray[0] * inputArray[0]
6. Create an instance method with the following definition.
public void addScalar (double inputArray, double scalar)
This method should update each cell in the inputArray by adding the value ‘scalar’ to each element in
the array
7. Create an instance method with the following definition.
public void multiplyByScalar (double inputArray, double scalar)
This method should update each cell in the inputArray by multiplying each cell by the value ‘scalar’
8. Create an instance method with the following definition. public double multiplyArrays (double inputArray, double inputArray2)
This method should return a new array whose cell is the result of multiplying the corresponding cells of
inputArray and imputArray2 (i.e. newarray[0] = inputArray[0] * inputArray2[0].
9. Create an instance method with the following definition.
public void subtractScalar (double inputArray, double scalar)
This method should update each cell in the inputArray by subtracting the value ‘scalar’ to each element
in the array. Part B
Use the methods you created above to implement the following functionality.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25. Create an array of type double and size 2000, and name it johnArray.
Initialize the array johnArray to values from 2000 down to 1
Calculate the sum of all element in johnArray and print the result.
Create a new array of type double and size 2000, and name it mariaArray.
Initialize the array mariaArray to values from 1 to 2000
Declare a new array of type double with the name johnReferenceArray
Assign johnArray to johnReferenceArray.
Create a copy of mariaArray and assign it to a variable named mariaCopyArray
Add the value 100 to all element of mariaCopyArray.
Print the sum of mariaCopyArray then print the sum of mariaArray. Are the two sums the same
or different? Why?
Add the value 100 to all element of johnReferenceArray.
Print the sum of johnReferenceArray, then print the sum of johnArray. Are the two sums the
same or different? Why?
Print the sum of johnArray, then multiply all element in the johnReferenceArray by the value 5,
and then print the sum of johnArray again? Are the two sums the same or different? Why?
Print the sum of mariaArray, then multiply all element in the mariaCopyArray by the value 5,
and then print the sum of mariaArray again? Are the two sums the same or different? Why?
Multiply the mariaArray and johnArray, and save the result in a new array called
mariaTimesJohnArray.
Print all element of the mariaTimesJohnArray
Calculate the sum of mariaTimesJohnArray.
Print the sum of all elements in the mariaTimesJohnArray.
-----------