Question: write enum Pitch that enumerates the 12 pitches of a musical scale. Seven of the pitches are labeled A, B, C, D, E, F,

write enum Pitch that enumerates the 12 pitches of a musical scale.
Seven of the pitches are labeled A, B, C, D, E, F,  
and G, and five are "half-way" pitches written as a letter and

 

write enum Pitch that enumerates the 12 pitches of a musical scale. Seven of the pitches are labeled A, B, C, D, E, F, and G, and five are "half-way" pitches written as a letter and a following "flat" symbol that is actually shown in the class diagram (we'll use a lowercase b for the full credit solution). Just write what the UML diagram tells you. Then write class Note with 2 private fields, 2 public constructors, and a public method as shown in the UML class diagram. When correctly written and compiled with class Song in file Song.java (that includes a public static main method, the final program will print the notes to "Mary Had a Little Lamb" to the console. Class Note represents a Pitch along with an octave. The seven main pitches are often named Do, Re, Mi, Fa, So, La, Ti, and then repeat to Do again, but the second Do is higher than the first (for us engineers, the sound has exactly twice the frequency). We call each repeated Do a new "octave", so our Note class has both a pitch and an octave field. The octave must be between -5 and 4, inclusive - so that's 7 regular and 5 flat pitches over 10 octaves, or 120 different notes. That should just about cover what our ears can hear! That's relative to "middle C", for your music majors! The default constructor should set the pitch field to null. This indicates no sound at all. The other constructor should assign each parameter to its corresponding field. For example, to assign parameter pitch to field pitch you would write this.pitch-pitch; because this.pitch always means "the member of the current class named pitch". Assigning constructor parameters to fields using this pattern is very common in Java constructors! Also validate the octave parameter - if it's less than -5, use -5, and if it's greater than 4, use 4. Don't worry, we'll learn how to correctly report parameter errors soon! Method toString() (be sure to use @Override) should return a space if field pitch is null. Otherwise, return a string representation of the Note by concatenating the pitch and (only if not zero) octave. So for a pitch of Eb and an octave of 2, you would return Eb2. Note that toString has NO PARAMETERS - listen to the old guy with the flashy light stick and use the fields, Luke. You may NOT add any getters to class "Note" to retrieve fields for your main method. Those fields are private - hands off! Instead, you may ONLY use the toString() method to format the fields for printing. Encapsulation! When compiled with the provided Song.java (you may NOT modify this file), our output should be exactly as shown - the notes for "Mary Had a Little Lamb". You do NOT need to provide screenshots, however, we'll run it ourselves -5 to 4 Song +main(args: String[]) Note -pitch: Pitch --octave: int +Note() +Note(pitch: Pitch, octave: int) +toString(): String "override>> enum> Pitch C Gb G Ab A Bb B Use lowercase b for b

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 Algorithms Questions!