Question: 1. Using the code below, In the Driver program create few objects and compare them. Then create a list of those objects and sort them.

1. Using the code below, In the Driver program create few objects and compare them. Then create a list of those objects and sort them.

2. Rewrite the Note class so that a list of Notes is sorted first by length of note and then within that by frequency.

public class NoteTester {

/**

Variables for the value and the length.

*/

private int length;

private int value;

public NoteTester(int len, int val) {

length = len;

value = val;

}

/**

Constructor

the length of the note and the value of the note.

*/

NoteTester() {

this.value = 0;

this.length = 4;

}

/**

Setter for The setLength method and setValue methods.

*/

public void setLength(int len) {

this.length = len;

}

public void setValue(int val) {

this.value = val;

}

/**

The getLength method getValue method.

*/

public int getLength(){

return this.length;

}

public int getValue(){

return this.value;

}

/**

Starting an Array for the note and finding the value of

the note. */

public String findNoteTester(){

String [] notes = {"A","A#",

"B","C","C#","D","D#","E","F","F#","G","G#"};

return notes[(value + 60) % 12];

}

/**

The getFrequency method returns the notes Frequency.

*/

public double getFrequency () {

double frequency = 440 * (Math.pow(2,value/12.0));

return frequency;

}

/////////////////////////////////////////////

public class DriverTest {

public static void main(String[] args) {

// TODO Auto-generated method stub

NoteTester m = new NoteTester(); // note input

m.setValue(20); // the value for the note

m.setLength(20); // the length for the note

String notes = m.findNoteTester();

double Freq = m.getFrequency();

}

}

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!