Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Please help with the following code. Thanks. Project Requirements: 1. The program wil a. Accept as input information about a song. This information will

Java: Please help with the following code. Thanks.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Project Requirements: 1. The program wil a. Accept as input information about a song. This information will include the name of the song and the notes for the song. b. Run in two modes of operation, one is for listening and the other is for interactive game play 2. Note Class a. This class should be used to store each note and to convert from a textual note, such as Db0 (D flat 0) to a frequency, 17.32. Additionally, all notes will need to be played for the duration specified in the input. b. Instance variables String note - text representation of note 11. double frequency-frequency of note double duration - length of time a note played iv.boolean badNote -indicates note is not valid (see table below for valid notes) c. Constructor I. Takes in a note and durations as Strings ii. Sets the note instance variable ii. Calls getHz which uses the note to set the frequency iv. Converts the duration parameter to a double and sets the duration(use Double.parseDouble API method) v. Catches BadNoteExceptions which prints the appropriate message and sets the badNote instance variable to true d. Methods i. Accessor method for note, frequency, duration and badNote(should be called isBadNote) setFrequency -private helper method ii. 1. sets the frequency value 2. Uses the octave and the key to calculate the notes frequency 3. Calculation is notes base frequency 2 (octave). See Notes Base Frequency chart below. Example A4 would be 27.5 2 4 or 440 hz. 4. Throws BadNoteException (See below)if Note key is invalid. ii playSound plays a sound. 1. Calls the Tone class's static method playNote(provided) 2. Passing the Note's frequency and duration to this static method. iv. equals(String anotherNote) 1. Takes in a String representing another Note's tone(A,B, C eto) 2. Compares the two Note's tones 3. Returns true if they match, false is they do not match. 3. Abstract Song Class a. Instance variables i. Array of Notes - holds the note object needed to play the song nameorsong String ll. noteNumber-int representing the current note being played b. Constructor i. Takes in the name of the song and a String array of Notes (A4, G3 etc) sets the name ong instance variable Uses the String array of Notes to fill the Array of Notes with Note objects iii. c. Methods i. getNameOfSong-accessor method for name of song ii. getNextNote-returns the next Note obiect in the arrav. ii. isEndOfSong returns true if end of song, false if not iv. toString-returns all the Notes in the array in a neatly formatted String 4. DemoSong class a. Extends Song Class no instance variables b. Constructor i. Takes in the name of the song and a String array of Notes, (A4, G3 etc) ii, Pass parameters to super class. c. Methods i. playDemo 1. Plays each note in the Song Array of notes. 2. Remember playSong method is in the Song class. 5. SongGame class a. Extends Song class b. The class must i. ii. Provide the name of the song Provide and play the first note Ask the user to guess the next note 1. If the user is correct play the note and ask for the next note 2. If incorrect print an error message and ask again for the next note iv. Provide the number of incorrectly guessed notes upon completion of the game. c. Much of the details of implementation of this class is left up to the developers. Use good coding practices. 6. BadNoteException a. Extends the Exception class b. User defined exception C. Thrown if invalid note used d. Constructor takes in a String representing an appropriate error message 7. Sample runs First Run Welcome to Glockenspiel Hero, the funnest game you'll build all week! Enter 'd' to play a demo of the song, of 'p' to play the game: p Guess the notes of the song "Mary Had a Little Lamb" The first note is A, which sounds like this Next note g Next note: f Great Job! You got a perfect score! Second Run Welcome to Glockenspiel Hero, the funnest game you'll build all week! Enter 'd' to play a demo of the song, of 'p' to play the game: p Guess the notes of the song "Mary Had a Little Lamb" The first note is A, which sounds like this Next note: e Sorry, that is not correct. Try again Next note: f Sorry, that is not correct. Try again Next note: d Next note g Next note: f You got 3 notes incorrect. Project Requirements: 1. The program wil a. Accept as input information about a song. This information will include the name of the song and the notes for the song. b. Run in two modes of operation, one is for listening and the other is for interactive game play 2. Note Class a. This class should be used to store each note and to convert from a textual note, such as Db0 (D flat 0) to a frequency, 17.32. Additionally, all notes will need to be played for the duration specified in the input. b. Instance variables String note - text representation of note 11. double frequency-frequency of note double duration - length of time a note played iv.boolean badNote -indicates note is not valid (see table below for valid notes) c. Constructor I. Takes in a note and durations as Strings ii. Sets the note instance variable ii. Calls getHz which uses the note to set the frequency iv. Converts the duration parameter to a double and sets the duration(use Double.parseDouble API method) v. Catches BadNoteExceptions which prints the appropriate message and sets the badNote instance variable to true d. Methods i. Accessor method for note, frequency, duration and badNote(should be called isBadNote) setFrequency -private helper method ii. 1. sets the frequency value 2. Uses the octave and the key to calculate the notes frequency 3. Calculation is notes base frequency 2 (octave). See Notes Base Frequency chart below. Example A4 would be 27.5 2 4 or 440 hz. 4. Throws BadNoteException (See below)if Note key is invalid. ii playSound plays a sound. 1. Calls the Tone class's static method playNote(provided) 2. Passing the Note's frequency and duration to this static method. iv. equals(String anotherNote) 1. Takes in a String representing another Note's tone(A,B, C eto) 2. Compares the two Note's tones 3. Returns true if they match, false is they do not match. 3. Abstract Song Class a. Instance variables i. Array of Notes - holds the note object needed to play the song nameorsong String ll. noteNumber-int representing the current note being played b. Constructor i. Takes in the name of the song and a String array of Notes (A4, G3 etc) sets the name ong instance variable Uses the String array of Notes to fill the Array of Notes with Note objects iii. c. Methods i. getNameOfSong-accessor method for name of song ii. getNextNote-returns the next Note obiect in the arrav. ii. isEndOfSong returns true if end of song, false if not iv. toString-returns all the Notes in the array in a neatly formatted String 4. DemoSong class a. Extends Song Class no instance variables b. Constructor i. Takes in the name of the song and a String array of Notes, (A4, G3 etc) ii, Pass parameters to super class. c. Methods i. playDemo 1. Plays each note in the Song Array of notes. 2. Remember playSong method is in the Song class. 5. SongGame class a. Extends Song class b. The class must i. ii. Provide the name of the song Provide and play the first note Ask the user to guess the next note 1. If the user is correct play the note and ask for the next note 2. If incorrect print an error message and ask again for the next note iv. Provide the number of incorrectly guessed notes upon completion of the game. c. Much of the details of implementation of this class is left up to the developers. Use good coding practices. 6. BadNoteException a. Extends the Exception class b. User defined exception C. Thrown if invalid note used d. Constructor takes in a String representing an appropriate error message 7. Sample runs First Run Welcome to Glockenspiel Hero, the funnest game you'll build all week! Enter 'd' to play a demo of the song, of 'p' to play the game: p Guess the notes of the song "Mary Had a Little Lamb" The first note is A, which sounds like this Next note g Next note: f Great Job! You got a perfect score! Second Run Welcome to Glockenspiel Hero, the funnest game you'll build all week! Enter 'd' to play a demo of the song, of 'p' to play the game: p Guess the notes of the song "Mary Had a Little Lamb" The first note is A, which sounds like this Next note: e Sorry, that is not correct. Try again Next note: f Sorry, that is not correct. Try again Next note: d Next note g Next note: f You got 3 notes incorrect

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions