OOP Lab Task 3

De la WikiLabs
Versiunea din 14 decembrie 2013 22:54, autor: Rhobincu (discuție | contribuții) (Pagină nouă: == Required Tutorials == * The Object Oriented Paradigm; Classes and Objects * Notions About the Java Language * Writing and Executing a Java Program * [[Java Syntax; A P...)
(dif) ← Versiunea anterioară | Versiunea curentă (dif) | Versiunea următoare → (dif)
Jump to navigationJump to search

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 of 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 String ([1]).
  • 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.