Java Assignment: Implementing MessageBufferADT for Message Management

Verified

Added on  2019/09/18

|1
|274
|248
Practical Assignment
AI Summary
This Java assignment focuses on implementing the MessageBufferADT interface, which involves creating a class to manage a buffer of messages. The assignment requires students to create a `Message` class and a `MessageBuffer` class that implements the `MessageBufferADT` interface. The `MessageBufferADT` includes methods for adding messages, removing the highest priority message, checking if the buffer is empty, and determining the size of the buffer. The provided code includes a `main` method to test the implementation by adding and removing messages. Desklib offers this assignment solution to help students understand and complete their Java programming assignments, providing a practical example of data structure implementation.
Document Page
import java.util.LinkedList;
public class Base_A11Q2 {
static class Message implements Comparable<Message> {
//TODO: complete class
}
static interface MessageBufferADT {
/**
* Adds one message to the buffer.
* @param m the message to be added to the buffer
*/
public void add(Message m);
/**
* Removes and returns the highest priority message in the buffer.
* @return the highest priority message in the buffer
*/
public Message remove();
/**
* Returns true if this buffer contains no elements.
* @return true if this buffer is empty
*/
public boolean isEmpty();
/**
* Returns the number of elements in this buffer.
* @return the integer representation of the size of the buffer
*/
public int size();
}
static class MessageBuffer implements MessageBufferADT {
//TODO: complete class
}
public static void main(String[] args) {
MessageBuffer messageBuffer = new MessageBuffer();
Message m3 = new Message("Bill", "08/07/2016", "8:08AM", 160);
Message m2 = new Message("Joseph", "09/05/2016", "2:35PM", 120);
Message m1 = new Message("Steve", "09/20/2016", "11:45PM", 60);
messageBuffer.add(m1);
messageBuffer.add(m2);
messageBuffer.add(m3);
System.out.println(messageBuffer.remove());
System.out.println(messageBuffer.remove());
System.out.println(messageBuffer.remove());
}
}
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
[object Object]