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. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.