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

De la WikiLabs
Jump to navigationJump to search
 
Linia 13: Linia 13:
 
== Requirements ==
 
== Requirements ==
  
* In method '''main''' of class '''TestClass''', instantiate on object of type [http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html java.io.FileOutputStream] in which to write, on each line, the contents of the fields of the formerly instantiated '''Message''' and '''SystemMessage''' objects, separating fields by the string "<->" (E.g.: "John<->Mary<->Hello!"). The name of the file in which the data is written is given as an argument of the '''main''' method, at runtime. '''NOTE:''' It is permitted to add an additional method in classes '''Message''' and '''SystemMessage''';
+
* In method '''main''' of class '''TestClass''', instantiate on object of type [http://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html java.io.FileOutputStream] in which to write, on each line, the contents of the fields of the formerly instantiated '''Message''' and '''SystemMessage''' objects, separating fields by the string "<->" (E.g.: "John<->Mary<->Hello!"). The name of the file in which the data is written is given as an argument for the '''main''' method, at runtime. '''NOTE:''' It is permitted to add an additional method in classes '''Message''' and '''SystemMessage''';
* Write a class '''StreamTester''' which should only contain the '''main''' method which should, just like the previous exercise, take a file name as an argument (the one written by the TestClass above). By using classes [http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html java.io.BufferedReader], [http://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html java.io.InputStreamReader] and [http://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html java.io.FileInputStream], read, line by line, the contents of the file, and then instantiate and print the appropriate objects ('''Message''' or '''SystemMessage'''). '''NOTE:''' You can use method '''split''' in class String ([http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String)]).
+
* Write a class '''StreamTester''' which should only contain the '''main''' method which should, just like the previous exercise, take a file name as an argument (the one written by the TestClass above). By using classes [http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html java.io.BufferedReader], [http://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html java.io.InputStreamReader] and [http://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html java.io.FileInputStream], read, line by line, the contents of the file, and then instantiate and print the appropriate objects ('''Message''' or '''SystemMessage'''). '''NOTE:''' You can use method '''split''' in class [http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#split(java.lang.String) java.lang.String].
 
* By catching exceptions thrown by the various methods used, if the file to read does not exist, the message "File not found" should be displayed in the console. If this file can't be read or written, "IO operation failed" should be displayed. If any of the lines written by '''StreamTester''' does not match the template, the message "Line <line content> does not match the expected template" should be printed, and the program should skip to the next line in the file.
 
* By catching exceptions thrown by the various methods used, if the file to read does not exist, the message "File not found" should be displayed in the console. If this file can't be read or written, "IO operation failed" should be displayed. If any of the lines written by '''StreamTester''' does not match the template, the message "Line <line content> does not match the expected template" should be printed, and the program should skip to the next line in the file.

Versiunea de la data 14 decembrie 2013 22:56

Required Tutorials

Requirements

  • In method main of class TestClass, instantiate on object of type java.io.FileOutputStream in which to write, on each line, the contents of the fields of the formerly instantiated Message and SystemMessage objects, separating fields by the string "<->" (E.g.: "John<->Mary<->Hello!"). The name of the file in which the data is written is given as an argument for the main method, at runtime. NOTE: It is permitted to add an additional method in classes Message and SystemMessage;
  • Write a class StreamTester which should only contain the main method which should, just like the previous exercise, take a file name as an argument (the one written by the TestClass above). By using classes java.io.BufferedReader, java.io.InputStreamReader and java.io.FileInputStream, read, line by line, the contents of the file, and then instantiate and print the appropriate objects (Message or SystemMessage). NOTE: You can use method split in class java.lang.String.
  • By catching exceptions thrown by the various methods used, if the file to read does not exist, the message "File not found" should be displayed in the console. If this file can't be read or written, "IO operation failed" should be displayed. If any of the lines written by StreamTester does not match the template, the message "Line <line content> does not match the expected template" should be printed, and the program should skip to the next line in the file.