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

De la WikiLabs
Jump to navigationJump to search
 
(Nu s-au afișat 8 versiuni intermediare efectuate de același utilizator)
Linia 7: Linia 7:
 
* [[Coding Conventions]]
 
* [[Coding Conventions]]
 
* [[Advanced Notions About Object Oriented Programming]]
 
* [[Advanced Notions About Object Oriented Programming]]
* [[Java Application Programming Interface (API) (EN)]]
 
* [[Exception Handling]]
 
* [[Input/Output Streams]]
 
  
 
== Requirements ==
 
== Requirements ==
  
# Write a class called '''ServerConfig''' which has the role of reading configuration values from a text file. This class will be used later on during the development of the server application, and needs to meet the following requirements:
+
* Create a Java application project, or open your previous one. The package name is <span style="font-family:'Lucida Console', monospace">labutil</span>.
#* The class needs to have two constructors:
+
* 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!
#*# One with an argument of type String, which represents the file to be read
+
<br>
#*# One without any arguments, which will implicitly consider the configuration file to be ''server.conf''.
+
* 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.
#* Objects of type '''ServerConfig''' have to read the file, line by line, and then expose the parameters that were read through methods.
+
* 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.
#* The methods in class '''ServerConfig''' must throw exceptions if any issues arise when reading or parsing the file:
+
<br>
#*# '''IOException''' if the file is missing or it cannot be opened (this exception is already being thrown by stream related classes, so you only need to rethrow it further up the execution stack).
+
* Add two constructors to this new class:
#*# '''InvalidFormatException''' if at least one line from the file doesn't match the expected pattern (this type of exception doesn't exist and it needs to be created).
+
** 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.
#*# '''UnknownKeyException''' if an unknown property is present in the file (this type of exception doesn't exist and it needs to be created).
+
** 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.
#*# '''MissingKeyException''' if one of the expected properties is missing from the file (this type of exception doesn't exist and it needs to be created).
+
<br>
#* The class must be immutable.
+
* '''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.
# The following properties are the only ones valid and must exist in the configuration file:
 
#* TCP_PORT - representing the TCP port on which the server will be listening on.
 
#* MAX_CLIENTS - the maximum number of clients that the server an serve.
 
# Write a test for this class (which should open a file, read its contents and print the read parameters on the screen) and add it to the main method in class '''Main'''.
 
  
 +
For example, if the original message was:
  
The configuration file that class '''ServerConfig''' is reading is a text file, containing lines of the following form:
 
 
<syntaxhighlight lang="xorg_conf">
 
<syntaxhighlight lang="xorg_conf">
PROPERTY=value
+
John:How are you?
 
</syntaxhighlight>
 
</syntaxhighlight>
* Any line starting with thr character #, preceded or not by spaces or "tab" characters is considered to be a comment and it will be ignored.
 
* Lines that do not contain any printable character but only spaces and/ or tabs will also be ignored.
 
* Spaces or tabs from the beginning and end of lines are ignored.
 
An example of a configuration file:
 
  
 +
The formatted reply message might be:
 
<syntaxhighlight lang="xorg_conf">
 
<syntaxhighlight lang="xorg_conf">
#this is a config file for the chat server!
+
Mary:I'm fine, thanks!
      #  this is made by ME!
+
----------
MAX_CLIENT=100
+
John:How are you?
      TCP_PORT=9000
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
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:
  
'''Notes:'''
+
<syntaxhighlight lang="xorg_conf">
* The three types of exceptions which must be defined have very simple implementations. You need to define them as classes that extend class '''Exception''' and they only need to contain a constructor with an argument of type String that only calls the constructor of the super-class of the same type.
+
John:I'm glad to hear that.
* The submitted files will be only Java implementations of the following classes: '''ServerConfig''', '''Main''', '''Message''', '''PrivateMessage''', '''InvalidFormatException''', '''UnknownKeyException''' and '''MissingKeyException'''.
+
----------
* The following classes and methods may be of use in implementing this assignment. Look them up in the API documentation:
+
Mary:I'm fine, thanks!
** String.trim
+
----------
** String.charAt
+
John:How are you?
** String.contains
+
</syntaxhighlight>
** String.startsWith
 
** String.equals
 
** String.split
 
** Integer.parseInt
 
** BufferedReader.readLine
 
* Because you can have two different objects of type '''String''' (with different references) which contain the same character sequence, and because operator == is used to compare references, the correct way to compare two Strings is by calling method equals:
 
<syntaxhighlight lang="java">
 
String a = "abc";
 
String b = new String(a);
 
if(a == b) { // <- wrong, this is evaluated to false
 
  //...
 
}
 
if(a.equals(b)) { // <- correct, this is evaluated to true
 
  //...
 
}
 
  
</syntaxhighlight >
+
<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:
 +
** 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
 +
<br>
 +
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.
 +
<br>
  
Submitting:
+
== Submitting ==
* The assignment is submitted attaching the Java source code files exclusively to an e-mail sent to radu.hobincu@upb.ro.
+
* The assignment will be evaluated automatically by the [http://homework.dcae.pub.ro:/WebObjects/Web-CAT.woa Web-CAT] platform.
* The subject of the e-mail will be [POO_3]
+
* You could access the Web-CAT platform using the username and the password with which you acces the <span style="color:red">electronica.curs.pub.ro</span> intranet.
* The body of the e-mail will contain the name and group of the student and any additional command you want to make.
+
* Select the OOP Lab Task 3 assignment.
* <font color="red">'''Attention'''</font>: Any deviation from these instructions may lead to the loss of the entire amount of points.
+
* Submit your work as a single .zip archive (give it whatever name you choose) containing only the Java source code files.
 +
* <font color="red">'''Attention'''</font> Any deviation from these instructions may lead to the loss of the entire amount of points.

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.