Program.java: mariaTimesJohnArray

$39.00

Category:

Description

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. Create an array of type double and size 2000, and name it johnArray.
9. Initialize the array johnArray to values from 2000 down to 1
10. Calculate the sum of all element in johnArray and print the result.
11. Create a new array of type double and size 2000, and name it mariaArray.
12. Initialize the array mariaArray to values from 1 to 2000
13. Declare a new array of type double with the name johnReferenceArray
14. Assign johnArray to johnReferenceArray.
15. Create a copy of mariaArray and assign it to a variable named mariaCopyArray
16. Add the value 100 to all element of mariaCopyArray.
17. Print the sum of mariaCopyArray then print the sum of mariaArray. Are the two sums the same or different? Why?
18. Add the value 100 to all element of johnReferenceArray.
19. Print the sum of johnReferenceArray, then print the sum of johnArray. Are the two sums the same or different? Why?
20. 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?
21. 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?
22. Multiply the mariaArray and johnArray, and save the result in a new array called mariaTimesJohnArray.
23. Print all element of the mariaTimesJohnArray
24. Calculate the sum of mariaTimesJohnArray.
25. Print the sum of all elements in the mariaTimesJohnArray.