I am working on how to add the contents of two arrays and putting the results on another array. The problem is that I am not too sure on how to do it properly.
The first array I called ary1. It is a double type with unknown length. This length is determined by my
JUnit test class.
The second array I labeled as ary2. ary2 is a copy of ary1. Therfore I casted it as the following in my adding arrays method.
Where y is a parameter passed from the NVectorADT interface. There isn't a return statement yet because I haven't determined what needs to be returned. I am thinking the result array.
Lastly the result array is a double where it's size is determined by the size of ary1. I created size field and in the constructor assigned size as ary1.length.
Here is the code of what I have done thus far.
Here are my thoughts of how to do this.
I know I am going to need a while loop that will terminate at the end of the length of ary1. I know in this loop I will need three for loops, in the first two for loops I need to mull through ary1 and ary2 and store each number in local variables. The last for loop will store the result of my caculation in the result array.
I am thinking the looping structure might look something like this.
While
for loop - ary1
for loop - ary2
for loop - store sum of ary1[i] and ary2[i] in aryResult[i]
end
However I don't know how to get a element in ary1, adding it to it's corresponding element in ary2 and putting the result in it's corresponding aryResult (ex. ary1[1] + ary2[1] = aryResult[1]). Also the thought has crossed my mind if I even will need three for loops. Couldn't I just use one for loop to mull through ary1 and ary2, do the operation, and store the result in aryResult?
Any thoughts would be appreciated.