The Chord class n the package you will create a reference class called chord. A
ID: 3841702 • Letter: T
Question
The Chord class n the package you will create a reference class called chord. A chord consists of a duration in seconds (a double value) and a sequence of frequencies (an array of double values). These will be the instance variables. It has the followingAPI: public Chord (double duration. double frequencies This is the constructor NB: Inthis constructor copy the values in the parameters frequencies to the instance variable frequencies. Use a for loop to do this public void play(): This plays the chord by calling the playChord method, a private method whose code is provided below. public string tos tring This returns a string version of a chord object. It should be formatted as the duration, followed by a colon, followed by the frequencies, a enclosed in square brackets. For example, if the durations is 1.5 and the frequencies are 440.0, 880.0, and 1760.0, this method would return [1. 5 440.0 880. 0 1760. oj The play Chord method: private void playchord (double duration double C1 frequencies final int slicecount int) (stdAudio. SAMPLE RATE duration final double slices E new double slice Count+1] for int i E 0 iExplanation / Answer
Hi, Please find my implementation of Chord class.
Please copy playChord() method that you have posted.
public class Chord {
private double seconds;
private double[] frequencies;
public Chord(double seconds, double[] frequencies) {
this.seconds = seconds;
this.frequencies = new double[frequencies.length];
for(int i=0; i<frequencies.length; i++)
this.frequencies[i] = frequencies[i];
}
public void play(){
playChord();
}
@Override
public String toString() {
String res = "["+seconds+": ";
for(int i=0; i<frequencies.length; i++){
if(i == frequencies.length-1)
res = res+frequencies[i];
else
res = res+frequencies[i]+" ";
}
res = res + "]";
return res;
}
// Copy playChord() method
}