Simple Java Task
- or -
Post a project like this1876
£30(approx. $38)
- Posted:
- Proposals: 4
- Remote
- #2304525
- Awarded
Description
Experience Level: Entry
This task needs to be completed by the end of 17th February (23:59:59 GMT) to the specification below, any questions please do not hesitate to ask :)
A priority queue is like a queue but when an item is added it is given a priority and it
will advance ahead of any items in the queue with lower priority (while remaining
behind items with the same priority or with higher priority). The primitive operations
are createpq, isempty, front (which should return the string from the front item in the
queue without any information about its priority), deletefront, frontpri (which should
return the priority of the front item), and addtopq (which should take two arguments, a
string and a priority).
You are required to write in Java a class that implements a priority
queue of strings with methods for all of the primitive operations (other than createpq,
which is not needed since the constructor should ensure
that any new priority queue object is empty). The class should also have a (Java)
toString method that generates a string of the form
. The data in the class must be private.
You are not allowed to make use of the PriorityQueue class from the Collections
Framework.
For this task priorities are to be represented by integers in the range 1 to 20, with 1
denoting the highest priority and 20 the lowest. The front, frontpri and deletefront
methods should throw/raise an exception when applied to an empty queue; the addtopq
method should throw/raise an exception if the priority is not in the range 1 to 20.
You should also write and submit code that tests the behaviour of all of the operations,
generating output indicating what methods are being called and what results are
returned and displaying the contents of the queue whenever changes are made. A
fragment of the output might look like:
Queue contents:
Adding ”ho” with priority 3
Queue contents:
Calling frontpri: 1 returned
Calling front: ”hello” returned
You should include code to test the behaviour of the front, frontpri, and removefront
operations when applied to an empty queue – this will require three separate try-catch or
try-except blocks. You should also test the behaviour of the addtopq method when
supplied with an out-of-range priority argument.
The test code should not be interactive.
The test code must be written in a main method in a separate class in a separate file
You may make use of any classes from the standard Java libraries (other than
PriorityQueue), but must not use any third-party classes.
A priority queue is like a queue but when an item is added it is given a priority and it
will advance ahead of any items in the queue with lower priority (while remaining
behind items with the same priority or with higher priority). The primitive operations
are createpq, isempty, front (which should return the string from the front item in the
queue without any information about its priority), deletefront, frontpri (which should
return the priority of the front item), and addtopq (which should take two arguments, a
string and a priority).
You are required to write in Java a class that implements a priority
queue of strings with methods for all of the primitive operations (other than createpq,
which is not needed since the constructor should ensure
that any new priority queue object is empty). The class should also have a (Java)
toString method that generates a string of the form
. The data in the class must be private.
You are not allowed to make use of the PriorityQueue class from the Collections
Framework.
For this task priorities are to be represented by integers in the range 1 to 20, with 1
denoting the highest priority and 20 the lowest. The front, frontpri and deletefront
methods should throw/raise an exception when applied to an empty queue; the addtopq
method should throw/raise an exception if the priority is not in the range 1 to 20.
You should also write and submit code that tests the behaviour of all of the operations,
generating output indicating what methods are being called and what results are
returned and displaying the contents of the queue whenever changes are made. A
fragment of the output might look like:
Queue contents:
Adding ”ho” with priority 3
Queue contents:
Calling frontpri: 1 returned
Calling front: ”hello” returned
You should include code to test the behaviour of the front, frontpri, and removefront
operations when applied to an empty queue – this will require three separate try-catch or
try-except blocks. You should also test the behaviour of the addtopq method when
supplied with an out-of-range priority argument.
The test code should not be interactive.
The test code must be written in a main method in a separate class in a separate file
You may make use of any classes from the standard Java libraries (other than
PriorityQueue), but must not use any third-party classes.
Jack A.
85% (4)Projects Completed
4
Freelancers worked with
4
Projects awarded
100%
Last project
17 Mar 2019
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies