Question: Create a reference class called Chord . It will contain two instance variables: duration , a double value indicating in seconds how long to play

Create a reference class called Chord. It will contain two instance variables: duration, a double value indicating in seconds how long to play a chord, and an array of double values that are the frequencies combining to make the chord.

The API will contain:

public Chord(double duration, double... frequencies), a constructor taking as parameters the duration and a varargs parameter of frequencies;

public void play(): this is simply the play method I provided for the group 4 assignment.

public double duration(): this is an accessor method that returns the value of the duration instance variable;

public double[] frequencies(): this method returns a copy of the array of frequencies; look at the Java Arrays library of static methods for one that performs this copy;

public String toString(): this method returns a string representing the chord, and which contains the duration followed by the list of frequencies;

public boolean equals(Chord that): this method returns true if and only if the two chords have identical frequencies; the durations do not have to be equal;

You will also write a program called PlayChordsFromFile. It reads in a text file containing pairs of lines. Each pair consists of a line with a single double value, which is the duration, followed by a line with a list of space-separated double values that are frequencies. The program should repeatedly read in two lines, create a Chord object from the values, and then place that Chord object on a queue.

To read one line of an arbitrary number of double values and return an array of those values, use this code:

String[] inputValues = StdIn.readLine().split("\\s+");

double[] frequencies = new double[inputValues.length];

for (int i = 0; i < frequencies.length; i++) {

frequencies[i] = Double.parseDouble(inputValues[i]);

}

The code assumes you have directed StdIn to read the data from the input file. Place this inside a while loop that continues while the input stream is not empty.

After the end of the input has been reached the program should repeatedly dequeue chords from the queue, playing each one, doing so until the queue is empty.

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!