OOP Lab Task 2

De la WikiLabs
Jump to navigationJump to search

Required Tutorials

Requirements

  • Create a Java application project whose name is oop_lab2.
  • Add to your project the class Message exactly as defined in OOP Lab Task 1.
  • Add another class, named Inbox, that encapsulates an array of Message objects. The Inbox class fields are:
    • a reference to an array of Message objects;
    • a constant that defines the size of the array;
    • two integers that denotes the index of the next free cell in the array and of the oldest unread message;
  • Add to the Inbox class a constructor without arguments that instantiates an array of Messages whose size is given by the constant field.
  • Add a method, named add, which does not return anything and has only one argument, a Message. The method put the new message in inbox at the location indicated by the index of the next free cell.
  • Add a method, named read, which takes no argument and returns the oldest message, as a formatted string containing the sender and the message content. This method calls one of the Message methods, and also advances the oldest unread message index to the next unread message. If there is no message to retrieve from the inbox, the method returns an empty string and does not advance the index.
  • Write another class called Main (the default class created if you created a project within NetBeans), which should contain only the main method, which instantiates an inbox, adds three messages to the inbox (either created in advance, or instantiated as parameters of the add method calls), and displays the messages read from the inbox (repeatedly calling the inbox read method - try to call it one more time, to see that no more message is displayed).

Submitting

  • The assignment will be evaluated automatically by the Web-CAT platform.
  • You could access the Web-CAT platform using the username and the password with which you acces the electronica.curs.pub.ro intranet.
  • Select the Task 2 assignment
  • To submit your work you upload a single .zip archive containing only the Java source code files.
  • Attention Any deviation from these instructions may lead to the loss of the entire amount of points.