Your program should accept input that represents notes and durations for some musical song,
convert this
input into numeric values, and use the StdAudio
class to play the notes on the computer's
speakers.
Each line of the input will consist of three values separated by different delimiters. The three values and the delimiters beween them, in order from left to right, are:pitch value (anHere is an example:Integer
)
"@" (the delimiter that separates notes from durations)
duration numerator (anInteger
)
"/" (the delimiter that separates numerator from denominator)
duration denominator (anInteger
)
12 @ 1/8Note that you should use thetrim
method of theString
class to remove all leading and trailing spaces from the parts of the input line that you split using"@/"
as the delimiters before processing the values in your program.
When the processing button is clicked by the user, the program should split the input entered by the user in the input area into separate strings for each line of the input. Then for each line,
- split the line into three values using the string
"[@/]"
as the delimiter (note: the square brackets inside the quotes are necessary to make thesplit
method work properly with two different delimiter characters in the input line)- trim off leading and trailing spaces from each of the three values obtained in the previous step
- convert the first value from the input line into an Integer value representing the pitch number
- convert the second value from the input line into a Double value representing the duration numerator
- convert the third value from the input line into an Integer value representing the duration denominator
- calculate the duration by dividing numerator by denominator
- include these two lines:
double[] aNote = StdAudio.note(pitch, duration); StdAudio.play(aNote);- that's the end of the for loop
StdAudio.java
class fileIn order to complete this assignment, you need to right-click on the following file and save it in the src folder of your NetBeans project:StdAudio.java
Your program should be able to process all of these inputs correctly:
For information about the StdAudio.java
class that is used in this assignment, see
pages 157 - 161 of the .pdf file that contains the material from
Chapter 1
of the textbook Introduction to Programming in Java, by Robert Sedgewick and Kevin Wayne.