Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write enum Pitch that enumerates the 1 2 pitches of a musical scale. Seven of the pitches are labeled A , B , C ,
write enum Pitch that enumerates the
pitches of a musical scale. Seven of the pitches are labeled A B C D E F and G and five are "halfway"
pitches written as a letter and a following "flat" symbol that is actually shown in the class diagram well use a
lowercase b for the full credit solution Just write what the UML diagram tells you you needn't sing them! :D
Then write class Note with private fields, 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 and inclusive so that's regular and flat
pitches over octaves, or 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 use and if it's greater than use Don't worry, we'll learn how to correctly report
parameter errors soon!
Method toStringbe 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 you would return Eb 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
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