Assignment 8.02: Programming (Extra Credit)
Attached Files:
File [login to view URL] (819 B)
In this assignment you will be implementing a linked list and a message queue.
Q1: Create a class called LibraryBook that contains the attributes of a library book, such as author, title, and year, as well as getters and a toString() method. See the UML diagrams below. Create a class called LibraryBookList, which is a linked structure that contains and manages LibraryBook objects. Create a Node class that contains each piece of data and points to the next node. Implement the add(), contains(), get(), remove(), getSize() and isEmpty() methods. The add() method needs to add books to the list and shift the element currently at a specified position in the list and add subsequent elements to the right (add one to their indices), contains() checks to see whether a particular LibraryBook exists in the list and returns true if it is in the list, and returns false if it is not in the list, get() retrieves a particular book in the list based on the index, remove() deletes the element at the specified position of the linked list and shifts the indices behind the removed book, getSize() returns the size of the bookList, and isEmpty() checks to see if the list is empty and if it is it returns true (if it is not empty, return false).
In your LibraryBookList class, using the Java sorting API, keep the books in alphabetical order by title. Refer to the Collections or Arrays classes for useful methods: [login to view URL] [login to view URL]
Note: You should not use Java's builtin list support (e.g., LinkedList, ArrayList). You must implement the linked data structure yourself from scratch. [25 points]
LibraryBook UML diagram
Q2: Make a driver class called LibraryMain. Create a LibraryBookList and add 4 LibraryBooks to the list, then remove the second and third books from the list. Check if the LibraryBookList is empty. Get the size of the LibraryBookList. Your output should match the output below: [5 points]
Sample output:
Books
Q3: Create a message queue that manages and incoming phone calls and messages in an answering machine. See [login to view URL] for a starting place and a description of the methods required in the message queue. Create a Message class that implements Comparable and contains the name of the caller, the date they called, the time, and the length of the call in seconds (as an integer). Make getters and a compareTo method that passes in another Message and compares the length of the messages. This method should compare the length of the two messages and return -1 if the first message is shorter than the second message, 0 if the length of the messages is equal, and 1 if the first message is longer than the second message.
All phone messages are enqueued into the message queue. The highest priority message in a message queue is the message with the shortest length. When dequeueing, your message queue should return the highest priority message, not follow the typical queue FIFO order. Messages should be removed from the queue when the phone call is returned.
In your driver class, create three Message objects and add them to a message queue. Enqueue the messages in an incorrect order (e.g. in ascending order by first name, date, or time). Print out the messages and call the dequeue() method. Note that you may not import any packages. See sample output below: [20 points]
Sample output:
MessageQueue
Hi - I am a professional Java Programmer- I have taken multiple courses on Data Structures, so this is right up my alley! - I've been programming in Java since last 5 years. I contribute to open source Java projects. You can see my code here ([login to view URL]). I also have formal CS education (Bachelors in Computer Science), So I have taken more then 7 courses where Java was used (Programming Intro, OOP, Data Structures, Algorithm Analysis, Operating Systems,Artificial Intelligence & Compiler Construction) - I write high quality fully commented code. Let me know if you have any questions. Thanks!
$15 USD på 1 dag
5,0 (53 anmeldelser)
5,9
5,9
3 freelancere byder i gennemsnit $38 USD på dette job