CSC 120 Programming Assignment 8 Option 3
Play a Song

Note: You should not work on this assignment during class-time unless:
  1. You have completed all of the in-class assigned work for the day, and
  2. You have permission from the instructor.

This assignment must be handed in to your instructor's handin folder before the beginning of class on the due date.

Description:

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.

Input format:

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   (an Integer)
"@"   (the delimiter that separates notes from durations)
duration numerator   (an Integer)
"/"   (the delimiter that separates numerator from denominator)
duration denominator   (an Integer)
Here is an example:
12 @ 1/8
Note that you should use the trim method of the String 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.

Outline of Processing Logic:

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,
  1. split the line into three values using the string "[@/]" as the delimiter (note:  the square brackets inside the quotes are necessary to make the split method work properly with two different delimiter characters in the input line)
  2. trim off leading and trailing spaces from each of the three values obtained in the previous step
  3. convert the first value from the input line into an Integer value representing the pitch number
  4. convert the second value from the input line into a Double value representing the duration numerator
  5. convert the third value from the input line into an Integer value representing the duration denominator
  6. calculate the duration by dividing numerator by denominator
  7. include these two lines:
        double[] aNote = StdAudio.note(pitch, duration);
        StdAudio.play(aNote);
    
  8. that's the end of the for loop

StdAudio.java class file

In 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

Input Samples to Use:

Your program should be able to process all of these inputs correctly:
  1. The musical scale
  2. Yankee Doodle
  3. The Entertainer
  4. Theme from Looney Tunes

Credits:

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.

It is expected that each student will complete this assignment INDIVIDUALLY.