Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Project Requirements: The program will Accept as input information about a song. This information will include the name of the song and the notes

Java

Project Requirements:

  1. The program will
    1. Accept as input information about a song. This information will include the name of the song and the notes for the song.
    2. Run in two modes of operation, one is for listening and the other is for interactive game play
  2. Note Class
    1. 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.
    2. Instance variables
      1. String note text representation of note
      2. double frequency frequency of note
      3. double duration length of time a note played
      4. boolean badNote indicates note is not valid (see table below for valid notes)
    3. Constructor
      1. Takes in a note and durations as Strings
      2. Sets the note instance variable
      3. Calls getHz which uses the note to set the frequency
      4. Converts the duration parameter to a double and sets the duration(use Double.parseDouble API method) .
      5. Catches BadNoteExceptions which prints the appropriate message and sets the badNote instance variable to true
  1. Methods
    1. Accessor method for note, frequency, duration and badNote(should be called isBadNote)
    2. setFrequency -private helper method
      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.

    1. playSound plays a sound.
      1. Calls the Tone classs static method playNote(provided)
      2. Passing the Notes frequency and duration to this static method.
    2. equals(String anotherNote)
      1. Takes in a String representing another Notes tone(A,B, C etc)
      2. Compares the two Notes tones
      3. Returns true if they match, false is they do not match.
  1. Abstract Song Class
    1. Instance variables
      1. Array of Notes holds the note object needed to play the song
      2. nameOfSong String
      3. noteNumber int representing the current note being played.
    2. Constructor
      1. Takes in the name of the song and a String array of Notes, (A4, G3 etc)
      2. Sets the nameOfSong instance variable
      3. Uses the String array of Notes to fill the Array of Notes with Note objects.
    3. Methods
      1. getNameOfSong accessor method for name of song
      2. getNextNote returns the next Note object in the array.
      3. isEndOfSong returns true if end of song, false if not
      4. toString returns all the Notes in the array in a neatly formatted String
  2. DemoSong class
    1. Extends Song Class no instance variables
    2. Constructor
      1. Takes in the name of the song and a String array of Notes, (A4, G3 etc)
      2. Pass parameters to super class.
    3. Methods
      1. playDemo
        1. Plays each note in the Song Array of notes.
        2. Remember playSong method is in the Song class.
  1. SongGame class
    1. Extends Song class
    2. The class must
      1. Provide the name of the song
      2. Provide and play the first note
      3. 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
      4. Provide the number of incorrectly guessed notes upon completion of the game.
    3. Much of the details of implementation of this class is left up to the developers. Use good coding practices.
  2. BadNoteException
    1. Extends the Exception class
    2. User defined exception
    3. Thrown if invalid note used.
    4. Constructor takes in a String representing an appropriate error message.
  3. 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

Sorry, that is not correct. Try again.

Next note: g

Next note: f

You got 3 notes incorrect.

  1. Create UML Class Diagram for the final version of your project. The diagram should include:
    1. All instance variables, including type and access specifier (+, -);
    2. All methods, including parameter list, return type and access specifier (+, -);
    3. Include Generalization and Aggregation where appropriate.
    4. The Driver does not need to be included.
    5. Refer to the UML Distilled pdf on the content page as a reference for creating class diagrams.
    6. A Link to a drawing program, Dia, is also posted on the content page.

Use the command line argument feature of Eclipse to pass in the song data.

I have the files for Driver.java, StdAudio.java, and Tone.java but they are fairly lengthy. If needed just write a comment.

Here is the .txt file

twinkle_twinkle.java

"Twinkle, Twinkle Little Star" C5 0.5 C5 0.5 G5 0.5 G5 0.5 A5 0.5 A5 0.5 G5 1 F5 0.5 F5 0.5 E5 0.5 E5 0.5 D5 0.5 D5 0.5 C5 1

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

Students also viewed these Databases questions

Question

=+4. Does the source have the ability to investigate this audience?

Answered: 1 week ago

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago