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

De la WikiLabs
Jump to navigationJump to search
 
Linia 11: Linia 11:
 
== Requirements ==
 
== Requirements ==
  
* Add two constructors to class '''Message''', accessible to all classes, one that should have arguments for all three fields ('''receiver''', '''sender''' și '''content'''), and one that should only have arguments for sender and content, receiver keeping its default '''null''' value;
+
* Write a class called '''PrivateMessage''' which will be used as a data carrier between a chat client and a specific recipient. This class needs to:
* Add access modifiers to the class members so that:
+
** Store the name of the sender, a message content and the name of the recipient;
** the three fields should only be accessible in the class; encapsulate them by adding ''getters'', accessible to all classes;
+
** Be immutable
** method '''print()''' should be accessible in all classes;
+
** Allow reading of the sender and content information from the Message objects in a way specific to private messages in chat programs: "(priv) sender: contents". This must be done with only one method call.
* Override '''toString()''' method (defined in '''java.lang.Object''' class) so that it returns a character string formed similarly with the chat messages: ''sender: receiver'';
+
** Have a way to read the message recipient from objects of type '''PrivateMessage'''.
* Create a class called '''SystemMessage''' which extends class '''Message'''. '''SystemMessage''' must contain an extra field of type ''int'' called '''type''', only accessible inside the class, and a ''getter'' for this field, accessible to all classes;
+
 
* Add two constructors to class '''SystemMessage''', accessible to all classes, one that should only take an argument for initializing field "type", and the second for initializing both "type" and "sender" (see [[Java Syntax; A Program's Lexical Structure#Class Constructors]] and [[Java Syntax; A Program's Lexical Structure#this and super Keywords]]).
+
* In the existing class '''Main''', instantiate at least 3 objects of type '''PrivateMessage''', and print for each one the formatted string and the recipient.
* Add three class constants to class '''SystemMessage''', of type '''int''', having values 0, 1 and 2, named ''TYPE_ERROR'', ''TYPE_OK'', and ''TYPE_CHANGE_NAME'';
+
 
* Override method '''toString()''' defined in class '''Message''', so that it only returns the value of field "type", as a String;
+
Notes:
* Change the instantiations in method '''main''' in class '''TestClass''' so that they use the new constructors. Add three more instantiations of object of type '''SystemMessage''' and display them in the console by using the '''toString()''' method.
+
* Each class and class member must have one of the three access modifiers ''public'', ''private'' or ''protected''.
 +
* The names of the classes must be identical to the ones specified above.
 +
* Use inheritance and overriding.
 +
 
 +
Submitting:
 +
* The assignment is submitted attaching the Java source code files exclusively to an e-mail sent to radu.hobincu@upb.ro.
 +
* The subject of the e-mail will be [POO_2]
 +
* The body of the e-mail will contain the name and group of the student and any additional command you want to make.
 +
* <font color="red">'''Attention'''</font> Any deviation from these instructions may lead to the loss of the entire amount of points.

Versiunea de la data 23 noiembrie 2014 20:16

Required Tutorials

Requirements

  • Write a class called PrivateMessage which will be used as a data carrier between a chat client and a specific recipient. This class needs to:
    • Store the name of the sender, a message content and the name of the recipient;
    • Be immutable
    • Allow reading of the sender and content information from the Message objects in a way specific to private messages in chat programs: "(priv) sender: contents". This must be done with only one method call.
    • Have a way to read the message recipient from objects of type PrivateMessage.
  • In the existing class Main, instantiate at least 3 objects of type PrivateMessage, and print for each one the formatted string and the recipient.

Notes:

  • Each class and class member must have one of the three access modifiers public, private or protected.
  • The names of the classes must be identical to the ones specified above.
  • Use inheritance and overriding.

Submitting:

  • The assignment is submitted attaching the Java source code files exclusively to an e-mail sent to radu.hobincu@upb.ro.
  • The subject of the e-mail will be [POO_2]
  • The body of the e-mail will contain the name and group of the student and any additional command you want to make.
  • Attention Any deviation from these instructions may lead to the loss of the entire amount of points.