Question: Need help with a Java problem please: The playChord method (copy/paste): private void playChord(double duration, double[] frequencies) { final int sliceCount = (int) (StdAudio.SAMPLE_RATE *

Need help with a Java problem please:

Need help with a Java problem please: The playChord method (copy/paste): private

The playChord method (copy/paste):

 private void playChord(double duration, double[] frequencies) { final int sliceCount = (int) (StdAudio.SAMPLE_RATE * duration); final double[] slices = new double[sliceCount+1]; for (int i = 0; i  

void playChord(double duration, double[] frequencies) { final int sliceCount = (int) (StdAudio.SAMPLE_RATE

When done correctly, you will have two files: a reference class in a file Chord.java and a program class PlayMusic.java.

Specifications For this assignment you will create a package called music. The Chord class In 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 following API: public Chord (double duration, double frequencies) This is the constructor. NB: In this 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 toString This returns a string version of a chord object. It should be formatted as the duration, followed by a colon, followed by the frequencies, all 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 C1. 5: 440.0 880.0 1760.01 The play Chord method: private void playChord(double duration, double frequencies) f final int slicecount (int) (StdAudio. SAMPLE RATE duration) final double CJ slices E new double slice Count+1]; for (int i 0; i slicecount i++) f double chord 0.0 for (double frequency: frequencies) chord Math sin (2 Math.PI i frequency StdAudio SAMPLE RATE) slices [i] chord/frequencies length; StedAudio. play (slices)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!