Question: Implement a method addData(double val) in the class below. public class MyArray { private double data[]; } If an element of data matches the

Implement a method addData(double val) in the class below. public class MyArray { private double data[]; } If an element of data matches the value, the array data remain the same. The method returns -1. Otherwise, reset the array data with one more element. Add the new value as the last element of the reset array. Return the index of the new value in the array data. Assume the array data initialized as data = new double[] {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3}; When calling the method addData(2.5), it returns 8. The elements in the updated array data are: {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3, 2.5} When calling the method addData(2.2), it returns -1. The elements are not changed. They are {1.5, 1.2, 3.7, 4.8, 2.2, 5.3, 1.1, 2.3}
Step by Step Solution
There are 3 Steps involved in it
Here is the implementation of the addData method based on the provided requirements public class MyA... View full answer
Get step-by-step solutions from verified subject matter experts
