Instructions This project focuses on queues and stacks. Following is the list of files that you need
for this project. DO NOT CHANGE ANYTHING IN THESE FILES. NOT EVEN A SINGLE LINE! -
StdAudio.java - Pitchjava - Accidentaljava - Note.java - Node.java - MelodyMainjava - Melody.java
You will add all of your methods to MelodyQueue.javaYour job is to complete the class that
represent a song: this class is called MelodyQueue. A song is comprised of a series of notes. It
may have repeated sections. As we don't like to have any redundancy, we will only store one copy
of a repeated chunk of notes. Music is usually printed like the example above. The notes are a
series of dots. Their position in relation to the lines determines their pitch and their tops and color,
among other things, determine their length. Since it would be difficult for us to read input in this
style, we will instead read input from a text file. An example input file is shown below: Each line in
it represents a single note. The first number describes the length of the note in seconds. The letter
that follows describes the pitch of the note, using the standard set of letters (AG) or R if the note is
a rest. For notes other than rests, the third item on the line is the octave that the note is in and the
following is the note's accidental value. The final piece of information for all notes is true if the note
is the start or stop of a repeated section and false otherwise. You will implement several methods
in the MelodyQueue class which will allow you to use MelodyMain to play your song with mp3
player like functionality. Your melody will be able to play as well as append another melody to
itself, reverse and have the it's tempo changed.You will add methods to the class:
MelodyQueue.java. You must use Java's Stack and Quetie from java.util. You must use them as
stacks and queues; you may NOT USE anything else that we have not discussed in the class such
as: iterators, iterables or anything of that sort. Your class must have the constructorsimethods
below. It must be possible to call the methods multiple times in any order and get the correct
results each time. Your MelodyQueue class will use a queue to store the notes in the song (all
quepes have pointer to the back and to the front). Bat unless otherwise specified, you may not
create any other auxiliary data structures (such as arrays, lists, stacks, quetes) to help you solve
any method below.MelodyQueue . java (for you to implement): public MelodyQueue () Constructor
with no parameters public void enqueue (Object item) Adds item to the back of the queue. Make
sure to cover the case that queue is null. public Object dequeue () Removes and returns item from
the front of queve. If the queue is null print a message that queve is null. public Boolean isEmpty ()
Checks if queue is empty. public double duration () Returns duration/time of queue. In other
words, it returns the total length of the song in seconds. If the song includes a repe.
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Instructions This project focuses on queues and stacks Foll.pdf
1. Instructions This project focuses on queues and stacks. Following is the list of files that you need
for this project. DO NOT CHANGE ANYTHING IN THESE FILES. NOT EVEN A SINGLE LINE! -
StdAudio.java - Pitchjava - Accidentaljava - Note.java - Node.java - MelodyMainjava - Melody.java
You will add all of your methods to MelodyQueue.javaYour job is to complete the class that
represent a song: this class is called MelodyQueue. A song is comprised of a series of notes. It
may have repeated sections. As we don't like to have any redundancy, we will only store one copy
of a repeated chunk of notes. Music is usually printed like the example above. The notes are a
series of dots. Their position in relation to the lines determines their pitch and their tops and color,
among other things, determine their length. Since it would be difficult for us to read input in this
style, we will instead read input from a text file. An example input file is shown below: Each line in
it represents a single note. The first number describes the length of the note in seconds. The letter
that follows describes the pitch of the note, using the standard set of letters (AG) or R if the note is
a rest. For notes other than rests, the third item on the line is the octave that the note is in and the
following is the note's accidental value. The final piece of information for all notes is true if the note
is the start or stop of a repeated section and false otherwise. You will implement several methods
in the MelodyQueue class which will allow you to use MelodyMain to play your song with mp3
player like functionality. Your melody will be able to play as well as append another melody to
itself, reverse and have the it's tempo changed.You will add methods to the class:
MelodyQueue.java. You must use Java's Stack and Quetie from java.util. You must use them as
stacks and queues; you may NOT USE anything else that we have not discussed in the class such
as: iterators, iterables or anything of that sort. Your class must have the constructorsimethods
below. It must be possible to call the methods multiple times in any order and get the correct
results each time. Your MelodyQueue class will use a queue to store the notes in the song (all
quepes have pointer to the back and to the front). Bat unless otherwise specified, you may not
create any other auxiliary data structures (such as arrays, lists, stacks, quetes) to help you solve
any method below.MelodyQueue . java (for you to implement): public MelodyQueue () Constructor
with no parameters public void enqueue (Object item) Adds item to the back of the queue. Make
sure to cover the case that queue is null. public Object dequeue () Removes and returns item from
the front of queve. If the queue is null print a message that queve is null. public Boolean isEmpty ()
Checks if queue is empty. public double duration () Returns duration/time of queue. In other
words, it returns the total length of the song in seconds. If the song includes a repeated section the
length should include that repeated section twice. For example, the sample file shown on previous
page have length 3.6. public double timeRepeat () This is an auxiliary method that you will call in
duration method. The job of this method is to find the duration of repeated sectionsReturns the
size of the queve public String makestring() Returns String version of the notes in the queve. In
other words, it returns a String containing information about each note. Each note should be on its
own line similar to example on page 2. Your String should reflect the changes that have been
made to the song by calling other methods. public void tempochange (double tempo) Changes the
tempo of each note to be tempo percent of what it formerly was. Passing a tempo of 1.0 will make
the tempo stay the same. Tempo of 2.0 will make each note twice as long, so it will be slower.
Tempo of 0.5 will make each note half as long (make it faster). Keep in mind that when the tempo
changes the length of the song also changes. public void playRepeat() Again, this is an auxiliary
2. method. You will use it in play method. The job of this method is to play the repeated sections.
public void appendMelody (MelodyQueue other) Adds one melody at the end of another one. In
other words, it adds all notes from the other song (input parameter) to the end of this song. For
example, if this song is A,F,G,B and the other song is F, C, D, your method should change this
song to be A, F, G, B, F, C, D. The other song should be unchanged after the call.public
MelodyQueue reverseMelody () Reverses the order of the notes of a song. This method reverses
the order of notes in the song, so that future calls to the play methods will play the notes in the
opposite of the order they were in before reverse was called. For example, a song containing
notes A, F, G, then B would become B, G, F, A. You must use a temporary Stack to help you solve
this problem. public void play () Plays the song. Must call the playRepeat method. This method
plays the song by calling each note's play method. The notes should be played from the beginning
of the queue to the end unless there are notes that are marked as being the beginning or end of a
repeated section. When the first note that is a beginning or end of a repeated section is found you
should create a second queue. You should then get notes from the original queue until you see
another marked as being the beginning or end of a repeat.As you get these notes you should play
them and then place them back in both queues. Once you hit a second marked as beginning or
end of a repeat you should play everything in your secondary queue and then retum to playing
from the main queue. It should be possible to call this method multinle times and get the same
result. B The yellow blocks represent notes with start or end of a repeat set to true. They and the
other notes in between them should be moved to a separate queue when played so that they can
be repeated.Note Class and Melody Class (provided): You are provided with a class named Note
class that your MelodyQueue use. A Note object represents a single musical note that will form
part of a melody. It keeps track of the length (duration) of the note in seconds, the note's pitch (A-
G, or R if the note is a rest), the octave, and the accidental (sharp, natural or flat). Each Note
object also uses keeps track of whether it is the first or last note of a repeated section of the
melody. The Melody class is just an Interface that will use the methods you created in your
MelodyQueve class. The Note class provides the following constructors and methods that you
should use in yourYou can look at the contents of the provided Notejava to answer any further
questions about how it wotks. Development Strategy and Hints: 1 suggest the following
development strategy for solving this project: 1. Add all of the describe methods to the
MelodyQueve class. Leave every method's body blank: if necessary, return a "dummy" value like
null or 0 . Get your code to run in the MelodyMain program, though the output will be incorrect. 2.
Implement the constructor, and the makeString methods: 3. Implement the deration and
changeTempo methods. You can check the results of the changeTempo method by reading in one
of the sample files, calling changeTempo and then calling the makestring method and cliecking
your output matches what you expected. 4. Complete the reverse and append methods. 5. Write
an initial version of play0 that assumes there are no repeating sections. 6. Add the play0) code
that looks for repeated sections and plays them twice, as described previously. You can test the
outpot of your program by running it on various inputs in the MelodyMain client. Other blats? Take
a look at the Node class. For the project 2, you worked with similar Node class but here the one
variable of the Node class is different: private cbject item? private Node nexti5. Wneramanat
verstouror phyonuaratssumes utre are io repeaimg seculous, 6. Add the play() code that looks for
3. repeated sections and plays them twice, as described previously. You can test the output of your
program by running it on various inputs in the MelodyMain client. Other hints: Take a look at the
Node class. For the project 2, you worked with similar Node class but here the one variable of the
Node class is different: private Object item; private Node next; For this project the item that one
Node will be holding is a Note with all its features (Pitch. duration...). We have a queve of nodes
where each Node holds a Note. You can check read method in MelodyMainjava to see how the
queue is populated with the Notes. In other words, how the song is created! Next question is how
we can play the song. For that, you don't have to do anything because in class Note the method
play is added. You just have to use it: To play the notes int the queue, I can traverse the queue
from front to back (the provided references for the queve). Remember this queue contains Nodes.
To access to the content of a Note that is saved in a Node, we have to do the following: (let's refer
to the Node as current): ( (Note) current.getrtem( ()) -play () ; We need to do the typecasting to
convert the Node to a Note, othervise we receive an error. Similarly in any other methods of the
MelodyQueue, whenever you need to get access to the Note inside a Node, you must do this
typecasting.II When the progran starts, type load and enter the name of the file you want to play II
You can then type play to hear it or any of the other comands to test your Melody's II other
functionality.private static void intro() { Systen.out.println("Melcone to MelodyMain. Type the word
in the left colum to do the action on the right"); Systen.out.printlin("load : load a new input file");
Systen.out.println("save : output to a file"); Systee. out.println("print : prints the contents of the last
loaded song"); System.out.printin("play : play the last loaded song"); System.out.println("reverse :
reverse the last loaded song"); System.out.println("duration : print out the length of the last loaded
song in seconds"); System.out.println("tempo : change the speed by a percentage");
System.out.printlin("append : appends notes from a second melody to the loaded one");
System.out.println("quit : exit the program"); } II Checks to eake sure the file exists. Prompts the
user for a new file until they II input a valid one. Returns a file that exists. Renember that the file
should be in the II sane project folder. public static File checkFile(String name, Scanner console) f
I File file = new File(name); while (Ifile.exists()) { System.out.print("Invalid file. File name? "); file=
new File( console.next ()); ). 3 II Returns a Melodyqueue filled with the notes specified in the
provided II Scanner. The notes will appear in the same order in the Melodyqueue II as they did in
the file. public static MelodyQueve read (Scanner input) f Melodyqueue song = new
Melodyqueve();lic class Note { private Pitch note; private double duration; private int octave;
private Accidental accidental; private boolean repeat; I/ pre : duration > and octave =1, //otherwise
throws an IllegalArgumentException II constructs a note with the provided duration, pitch, octave,
accidental and repeat settings. public Mote(double duration, Pitch note, int octave, Accidental
accidental, boolean repeat) { if(duration <= octave < octave >10){ throw new
IllegalArgumentException(); 3 this. note = note; this.duration = duration; this octave = octave; this .
accidental = accidental this .repeat = repeat; 3 II pre : duration >, otherwise throws an
IllegalArgumentException II constructs a note with the passed in duration, pitch and repeat
settings. public Mote(double duration, Pitch note, boolean repeat) { this(duration, note, ,
Accidental.MATURAL, repeat); 3 II returns the length of the note in secondsII constructs a note
with the passed in duration, pitch and repeat settings. public Mote(double duration, Pitch note,
boolean repeat) { this(duration, note, 0 , Accidental.MATURAL, repeat); } II returns the length of
4. the note in seconds public double getDuration() { return duration; } II returns the Accidental value
of the note public Accidental getAccidental() { return accidental; } II returns the octave of the note
public int getoctave() { return octave; } II returns the pitch of the note (A - G or R of it is a rest)
public Pitch getpitch() { return note; 3 II pre : d must be greater than , otherwise an
IllegalArgumentException is thrown II sets the duration of the note to be the given time public void
setDuration(double d) { if (d<=){ throw new IllegalArgumentException(); pre : d must be greater
than , otherwise an IllegalArgumentException is thrown II sets the duration of the note to be the
given time public void setDuration(double d) { if (d<=){ throw new IllegalArgumentException();
duration =d; I/ sets the accidental of the note to be the given accidental public void
setAccidental(Accidental a) { accidental =a } // pre : octave must be greater than 0 and less than
10, II otherwise an IllegalArgumentException is thrown II sets the octave of the note to be the
passed in octave public void set0ctave(int octave) { if(octave <0 octave >10 ) { throw new
IllegalArgumentException(); } this octave = octave; 3 II sets the pitch of the note to be the passed
in pitch public void setPitch(Pitch pitch) { note = pitch; }I/ sets the pitch of the note to be the
passed in pitch public void setpitch(Pitch pitch) { note = pitch; I/ sets the repeat of the note to be
the passed in repeat public void setRepeat(boolean repeat) { this. repeat = repeat; } II returns true
if the note is the beginning or ending note in a repeated section, II false otherwise public boolean
isRepeat() { } II plays the sound this note represents public void play() { StdAudio.play(duration,
note, octave, accidental); II Otherwise returns a string in the format: public String tostring() { 4
SHARP true" and "1.5 R true". if(note.equals(Pitch. R )) { } else {I/ plays the sound this note
represents public void play() { } StdAudio.play(duration, note, octave, accidental); II otherwise
returns a string in the format: II For example "2.3 A 4 SHARP true" and "1.5 R true". public String
tostring() { if(note.equals(Pitch.R)) { return duration ++ note ++ + + repeat; } else { 3 return
duration +"+ note +"+ octave +" " + accidental +"=+ repeat; }public class MelodyQueve { private
Node front; private Node back; //Add all of your methods to this class. DO NOT CHAVGE ANY
OTHER CLASSESIIII public MelodyQueve() front = null; back = null; } public void enqueve (Object
item){ 33