Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Specify, design and implement a class that can be used to hold information about

ID: 3550786 • Letter: S

Question

Specify, design and implement a class that can be used to hold information about a musical note.

A programmer should be able to set and retrieve the length of the note and the value of the note. The length of a note may be a sixteenth note, eight note, quarter note, half note, or a whole note.

A value is specified by indicating how far the note lies above or below the A note that orchestras use in tuning. in counting "how far", you should include both the while and black notes on a piano.

Write a complete java program

+ The default constructor should set a note to a middle C quarter note.

+ Include methods to set a note to a specified length and value.

+ Write methods to retrieve information about a note, including methods to tell you the letter of the note (A, B , C)

   -  Whether the note is natural or sharp (i.e.. white or black on the piano), and the frequency of the note in hertz.
    - To calculate the frequency, use the formula 440 x 2^(n/12) where n is the note number.

Explanation / Answer

import java.io.BufferedReader;

import java.io.InputStreamReader;



class Note

{

double length;

String value;

Note()

{

value="C";

}

Note(double length,String value)

{

this.length=length;

this.value=value;

}

public double getLength() {

return length;

}

public void setLength(double length) {

this.length = length;

}

public String getValue() {

return value;

}

public void setValue(String value) {

this.value = value;

}

}


public class MusicalNote {

public static void main(String args[])

{

System.out.println("Enter note length");

try

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

double l=Double.parseDouble(br.readLine());

String c=br.readLine();

Note n=new Note(l,c);

double frequency;

frequency=440 *( Math.pow(2,(n.getLength()/12)));

System.out.println("Note Length:"+n.getLength);

System.out.println("Note Value:"+n.getValue);

System.out.println("Note Frequency:"+frequency);

}

catch(Exception e)

{

System.out.println(e);

}

}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote