Diferență între revizuiri ale paginii „OOP Lab Task 3”

De la WikiLabs
Jump to navigationJump to search
 
(Nu s-au afișat 2 versiuni intermediare efectuate de același utilizator)
Linia 10: Linia 10:
 
== Requirements ==
 
== Requirements ==
  
* Create a Java application project whose package name is <span style="font-family:'Lucida Console', monospace">oop_lab3</span>.
+
* Create a Java application project, or open your previous one. The package name is <span style="font-family:'Lucida Console', monospace">labutil</span>.
* Add to your package the classes '''Message''' and '''Inbox''' exactly as defined in OOP Lab Task 2. Do not modify them!
+
* Add to your project (if they are not already there) the classes '''Message''' and '''Inbox''' exactly as defined in OOP Lab Task 2. You may copy them from your uploaded archive of the previous assignment on the Web-CAT. Do not modify them!
 
<br>
 
<br>
* 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.
+
* 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 replies. The attached message may be in its turn a simple message or a full 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.
+
* The '''FullMessage''' class additional field is the reference to the attached message. This field is immutable and private, as are the fields of the base class.
 
<br>
 
<br>
 
* Add two constructors to this new 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 three arguments, two strings for the sender's name and the reply text, 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.
+
** a constructor with two arguments, strings for the sender's name and the content of the message. This constructor instantiates a full message but without any attachment. Use a call to the previous constructor.
 
<br>
 
<br>
* '''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.
+
* '''FullMessage''' class must override both read methods of the class Message, such that they return the formatted string for the sender and content (as stated for the '''Message''' class read methods), followed, if there is an attachment, by a delimiter on a separate line ("----------"), after which goes the formatted string of the attached message.
  
 
For example, if the original message was:
 
For example, if the original message was:
Linia 37: Linia 37:
 
Notes:
 
Notes:
 
* Be sure, when you format the string, that the original message exists, otherwise format the full message as a simple message.
 
* 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.
+
* Since the base class fields are private you must rely on the base class read methods to get the formatted string of it's sender and content.
 +
* If the attached message has also an attachment, format it as stated for any full message:
 +
 
 +
<syntaxhighlight lang="xorg_conf">
 +
John:I'm glad to hear that.
 +
----------
 +
Mary:I'm fine, thanks!
 +
----------
 +
John:How are you?
 +
</syntaxhighlight>
 +
 
 
<br>
 
<br>
 
* 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:
 
* 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:

Versiunea curentă din 20 noiembrie 2016 21:00

Required Tutorials

Requirements

  • Create a Java application project, or open your previous one. The package name is labutil.
  • Add to your project (if they are not already there) the classes Message and Inbox exactly as defined in OOP Lab Task 2. You may copy them from your uploaded archive of the previous assignment on the Web-CAT. 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 replies. The attached message may be in its turn a simple message or a full 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 attached 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's name and the reply text, 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's name 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 (as stated for the Message class read methods), followed, if there is an attachment, 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 it's sender and content.
  • If the attached message has also an attachment, format it as stated for any full message:
John:I'm glad to hear that.
----------
Mary:I'm fine, thanks!
----------
John:How are you?


  • 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.