write enum Pitch that enumerates the 12 pitches of a musical scale. Seven of the pitches...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
2. There are different kinds of statistical analyses, and you will need to use one that is best suited to the data available and the information you need to collect in the given scenario (Good Days)....
-
Alice owns undeveloped land with an adjusted basis of $160,000. She sells the property to George for $205,000. a. What is Alice's realized and recognized gain? b. To what IRC section does the gain on...
-
The initial margin on a GBP futures contract is $2035 and maintenance is $1850. You buy one contract (62,500 Pounds) at $1.3100 and place $2035 in your account. The price of your contract drops to...
-
Laghari & Lagharis Personnel Department maintains a file of all employees of the company and each employees unique Employee ID. The file llemployees provides information on employees for Laghari &...
-
Although buried by mass customization and a proliferation of new products of numerous sizes and variations, grocery chains continue to seek to maximize payoff from their layout. Their layout includes...
-
2. a) Illustrate how BUILD-MAX-HEAP (A) works on the array A = {2, 9, 6, 8, 11, 4, 5, 3, 1, 7}. Each step is the result of one call to the MAX-HEAPIFY function. Show both the array view and the tree...
-
The Metropolis Health Systems Rehabilitation and Wellness Center offers outpatient therapy and return-to-work services plus cardiac and pulmonary rehabilitation to get people back to a normal way of...
-
C. Prepare the Balance Sheet as of 30 June 2020 using the following template: Maloney Co-Balance Sheet as of 30 June 2020 Current Assets Bank Accounts Receivable Inventory Prepaid Expenses $ $ $ $ $...
-
How do ethical frameworks such as deontology, consequentialism, and virtue ethics inform decision-making in complex socio-technological environments?
-
How External auditors may qualify for whistleblower awards? Explain in detail. they report information about potential violations of their audit firm's performance of audit services for the client...
-
How is the recognition of a recovery different from the recognition of a gain? Can a recovery be recorded as income? Why or why not?
-
What is the definition of a deficient evaluation is that it includes irrelevant considerations?
-
Recovery is a process of change through which people improve their health and wellness, live self-directed lives, and strive to reach their full potential. Even people with severe and chronic...
-
At December 31, 2020, Albrecht Corporation had outstanding 353,000 shares of common stock and 20,000 shares of 9.5%, $100 par value cumulative, nonconvertible preferred stock. On May 31, 2021,...
-
If a process has a six-sigma capability, what is the process capability index? a. 1 b. 2 c. 6 d. 12
-
Find P(A or B) for the following. a. P(A) = .28, P(B) = .39, and P(A and B) = .08 b. P(A) = .41, P(B) = .61, and P(A and B) = .19 Given that A and B are two mutually exclusive events, find
-
Refer to Problem 11. Assume that a preliminary study has shown that 70% of the students surveyed at this college are dissatisfied with the current online registration system. How large a sample...
-
Let x be a continuous random variable that follows a distribution skewed to the left with = 90 and = 18. Assuming n/N < .05, find the probability that the sample mean, x , for a random sample of 64...
-
A copper sheet of thickness \(2 L=2 \mathrm{~mm}\) has an initial temperature of \(T_{i}=118^{\circ} \mathrm{C}\). It is suddenly quenched in liquid water, resulting in boiling at its two surfaces....
-
The heat transfer coefficient for hydrogen flowing over a sphere is to be determined by observing the temperature-time history of a sphere fabricated from pure copper. The sphere, which is \(20...
-
A power transistor mounted on a finned heat sink can be modeled as a spatially isothermal object with internal heat generation and an external convection resistance. (a) Consider such a system of...
Study smarter with the SolutionInn App