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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started