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.
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.
Step by Step Solution
3.36 Rating (165 Votes )
There are 3 Steps involved in it
From exercise E712 the Sequence class is basically a wrapper for an int array with methods to intera... View full answer
Get step-by-step solutions from verified subject matter experts
