I have to pass the values that are in my Guitar constructor and then pass them to the generateSong method. There is one catch. The generate song method can not take parameters in because since the values are in the same class, they should be able to be able to take in the values from the constructor.
When I try to implement the values in that method, the values are not able to be accessed. How can I fix this?
public Guitar(int chord, int numOfStrings) {
//pass these values to the generateSong method
System.out.println("Guitar () generated a guitar with: " + numOfStrings + "." + "Song length is " +chord);
// declare the array for which the song is stored
// store the values of the last row i (highest index of the array)
double[] max = null;
Guitar.generateSong();
// start the generate song method
public static void generateSong () {
double [] [] song = new double [numOfStrings] [chord];
double[] max;
int findmax =0;
int sum =0;
for (int i =0; i<song.length; i++) {
for (int j =0; j<song.length; j++ ) {
sum = (int) (sum +song[i][j]);
}
for (int e=0; e<song.length; e++) {
if (song[e]!=song[findmax] ) {
max[e] =e;
}
for(int k=0; k<song.length; k++) {
for (int l=0; k<song[k].length; k++)
// assign note values to the array
song [k] [l] = 27.5 + (Math.random()* 4186);
// print out the proper value
System.out.printf("8.2%f", song);
for( int m=0; m<max.length; m++)
max[m]= 1 +( Math.random() *3);
System.out.printf("8.2%f", max);
}
}
}
}
The values int chord and int numOfStrings come from command line parameters in the main method and are passed to this method through the following object:
Guitar guitar = new Guitar (numOfStrings, chord);