Add a method public Sequence sum (Sequence other) to the Sequence class of Exercise E7.12 that

Question:

Add a method public Sequence sum (Sequence other) to the Sequence class of Exercise •• E7.12 that yields the sum of this sequence and another. If the sequences don’t have the same length, assume that the missing elements are zero. For example, the sum of 1 4 9 16 9 7 4 9 11 and 11 11 7 9 16 4 1 is the sequence 12 15 16 25 25 11 5 9 11.

Data from exercise E7.12

Consider the following class:
public class Sequence {
private int [] values;
public Sequence(int size) { values = new int[size]; }
public void set(int i, int n) { values[i] = n; }
public int get(int i) { return values[i]; }
public int size () {return values.length;}
}
Add a method public boolean equals (Sequence other) that checks whether two sequences have the same values in the same order.


Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question
Question Posted: