Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a reference class called EqualTemperedFrequency . Have it implement the C

ID: 3551050 • Letter: C

Question

Create a reference class called EqualTemperedFrequency. Have it implement the Comparable interface

The class will contain a single double value that is a sound frequency. The API for the class should contain the following constructor and methods:





package assignment4solutions;


import stdlib.*;


public class EqualTemperedFrequency implements Comparable<EqualTemperedFrequency> {

public final Double frequency;

//This constructor sets the sound frequency of this object to the initial value supplied

public EqualTemperedFrequency(Double initialValue)

{ this.frequency = initialValue; }

public double EqualTemperedFrequency next() {

double nextFrequency;

nextFrequency = this.frequency*Math.pow(2.0, 0.83);

return nextFrequency;}

public void play(double duration){

final int sliceCount=(int)(StdAudio.SAMPLE_RATE * duration);

final double[] slices = new double[sliceCount + 1];

for(int i = 0; i < sliceCount; i++){

slices[i] = Math.sin(2 * Math.PI * i * this.frequency / StdAudio.SAMPLE_RATE);

}

}

public String toString(){

String frequencyConversion = Double.toString(frequency);

return frequencyConversion;

}

public int CompareTo(EqualTemperedFrequency that){

if(this.frequency < that.frequency) { return -1;}

if(this.frequency > that.frequency) { return +1;}

return 0;

}

public boolean isLessThanOrEqual(EqualTemperedFrequency that){

if(this.frequency <= that.frequency) { return true;}

return false;

}

}

Explanation / Answer

I think there is no flaw in the code. Its perfect. I dont know how play works. Please check it and i think you are good to go. :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote