OOP Lab Task 3
De la WikiLabs
Required Tutorials
- The Object Oriented Paradigm; Classes and Objects
- Notions About the Java Language
- Writing and Executing a Java Program
- Java Syntax; A Program's Lexical Structure
- Coding Conventions
- Advanced Notions About Object Oriented Programming
Requirements
- Create a Java application project whose package name is oop_lab3.
- Add to your package the classes Message and Inbox exactly as defined in OOP Lab Task 2. Do not modify them!
- Create a new class FullMessage derived from the class Message. This class allows the creation of messages that are replies to other messages, such that a reply message has as an attachment the original message to which it replied. The original message may be in its turn a simple message or a reply message, in the latter case being a whole chain of reply to reply to reply a.s.o.
- The FullMessage class additional field is the reference to the original message. This field is immutable and private, as are the fields of the base class.
- Add two constructors to this new class:
- a constructor with three arguments, two strings for the sender and the content, and a reference to the original message. In its implementation use a call to the base class constructor.
- a constructor with two arguments, strings for the sender and the content of the message. This constructor instantiates a full message but without any attachment. Use a call to the previous constructor.
- FullMessage class must override both read methods of the class Message, such that they return the formatted string for the sender and content followed by a delimiter on a separate line ("----------"), after which goes the formatted string of the attached message.
For example, if the original message was:
John:How are you?
The formatted reply message might be:
Mary:I'm fine, thanks!
----------
John:How are you?
Notes:
- Be sure, when you format the string, that the original message exists, otherwise format the full message as a simple message.
- Since the base class fields are private you must rely on the base class read methods to get the formatted string of the sender and the content.
- 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, creates four messages, adds them to the inbox, 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). That four messages will be:
- a simple message
- a full message that is a reply to the first message
- another full message but without any attachment
- a full message that is a reply to the second (full) message
Notes:
- Though the Inbox object has an array of Message references you are still able to add full messages to the inbox because they are of type Message by inheritance.
- The overriding allows you to read full messages from the inbox, despite the fact that internally they are referred to as Message objects.
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 OOP Lab Task 3 assignment.
- Submit your work as a single .zip archive (give it whatever name you choose) containing only the Java source code files.
- Attention Any deviation from these instructions may lead to the loss of the entire amount of points.