You are given a file chords. txt where each line contains three double values. T
ID: 3823013 • Letter: Y
Question
You are given a file chords. txt where each line contains three double values. The first value is a duration and the second and third values are frequencies. Place this file into the data folder on Eclipse. Once again you are to read values in from a file but you must be careful in doing this as different values mean different things. After you open the file, follow this pseudocode While not at the end of file for StdIn declare an array of length 2 the duration for i in the range 0 to 1 read the frequency into the ith frequencies array entry end play the chord end Note that we are now using nested loops. To play a chord, you will need a different method and that's included here: public static void playchord (double duration, doubleCJ frequencies) final int slicecount (int) (Std Audio. SAMPLE RATE duration) final double slices new double[sliceCount+1]; for int i 0; i slicecount i++) double chord 0.0 for double frequency frequencies) chord Math.sin (2 Math. PI i frequency StdAudio.SAMPLE RATE) slices [i chord/frequencies .length StdAudio.play(slices)Explanation / Answer
Java Program For the Given Algorithm:-
To Do tasks:-
1: Paste the input File location in the Path mentioned in the Program
2: Paste the PlayChord(double duration. double frequencies[]) in the location mentioned in the Program.
public class FileRowPrinter {
public static void main(String[] args) throws IOException{
FileInputStream fis = null;
BufferedReader input = null;
//Provide your File input path where the input file is present
fis = new FileInputStream("");
input = new BufferedReader(new InputStreamReader(fis));
String line = input.readLine();
while(line != null){
String[] array = line.split(" ");
double duration = Double.valueOf(array[0]);
Double[] frequencies = new Double[2];
frequencies[0] = Double.valueOf(array[1]);
frequencies[1] = Double.valueOf(array[2]);
playChord(duration, frequencies);
line = input.readLine();
}
}
private static void playChord(double duration, Double[] frequencies) {
//Paste your Method Code here from the Given Question
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.