Class name: Music
Method name: nameThatTune
Parameters: String[], String
Returns: int
Implement a class Music, which has a method nameThatTune.
Method signature: int nameThatTune(String[] Library, String Tune) (be sure you
declare your method public)
*Library has between 1 and 10 Strings, inclusive.
*Each String in Library has between 1 and 50 characters, inclusive.
*Tune has between 1 and 50 characters, inclusive.
Each element in Library is a String that represents a song, as is Tune. The
given Tune (and each element of Library) is made up of notes from the following
note sequence, each note is separated by a pipe (the vertical bar) :
C|C#|D|D#|E|F|F#|G|G#|A|A#|B
The following is true about the note sequence :
1) All the notes in the note sequence are an equal distance between each other.
2) Each note in the sequence occupies one position in the sequence.
(i.e. C occupies one position, C# occupies one position,
D occupies one position, D# occupies one position, et cetera)
3) The sequence wraps around (i.e. C follows B).
4) The note sequence represents the notes from which the Tune is composed.
5) All of the notes are represented by uppercase characters.
Tune A and Tune B are the same if either
1) The sequence of notes in Tune A and Tune B are identical.
2) A Translation of Tune B is equal to Tune A.
Note: Tune A and Tune B must have the same amount of notes to be considered the
same.
A translation is just a replacement of the notes in a tune by other notes that
retain their relative distances between each other. The distance is computed
by adding the number of positions between the starting note and the ending note
counting from left to right.
Distance Example
D is two places to the right of C, therefore the distance between C and D is two
D# is one place to the right of D, therefore the distance between D and D# is one
C is one place to the right of B, therefore the distance between B and C is one
Translation Example:
"C|D|E" is a translation of "F|G|A" (C is the same distance from F as D is to
G and E is to A)
"E|F|F#" is a translation of "C|C#|D"
"C|E|G" is a translation of "G|B|D"
"A|B|C" is a translation of "D|E|F" and of "G|A|A#"
*nameThatTune returns the number of Strings in Library that are the same as Tune
Example:
Library: Tune:
"A|B|C|B|A" "A|B|C|B|A"
"A|D|F|C#"
"B|C#|D|C#|B"
"A|B|C|B|A" is in Library, and "B|C#|D|C#|B" is a translation of "A|B|C|B|A",
so nameThatTune returns 2.
Test Cases:
1) Library = {"C|E|G", "G|B|D", "A|C#|E", "A|C#|D" } Tune = "C|E|G" returns 3
2) Library = { "C|E|G", "G|B|D", "A|C#|E", "A|C#|D" } Tune = "B|C|G" returns 0
3) Library = { "C|C|E|E|A|A|C|C|F|F|A|A|G|G|B|B", "E|D#|E|D#|E", "C|E|G|C" }
Tune = "G|B|D|G" returns 1.
4) Library = { "C|C|E|E|A|A|C|C|F|F|A|A|G|G|B|B", "E|D#|E|D#|E", "C|E|G|C" }
Tune = "A|A|C#|C#|F#|F#|A|A|D|D|F#|F#|E|E|G#|G#" returns 1.
5) Library = { "C|C|E|E|A|A|C|C|F|F|A|A|G|G|B|B", "E|D#|E|D#|E", "C|E|G|C" }
Tune = "C|B|C|B|C" returns 1.
6) Library = { "C|C|E|E|A|A|C|C|F|F|A|A|G|G|B|B", "E|D#|E|D#|E", "C|E|G|C" }
Tune = "C|B|C|B|D" returns 0.