0% found this document useful (0 votes)
12 views

Tutorial 10

The document provides instructions and guidelines for 4 exercises involving building utility classes for reading/writing files and binary objects to files, representing matrices and matrix operations, and performing operations on text files. The exercises involve building classes and methods to copy files, read/write objects to files, perform matrix sums and products, and count lines, write, print, copy, and delete text files.

Uploaded by

pilot250504
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Tutorial 10

The document provides instructions and guidelines for 4 exercises involving building utility classes for reading/writing files and binary objects to files, representing matrices and matrix operations, and performing operations on text files. The exercises involve building classes and methods to copy files, read/write objects to files, perform matrix sums and products, and count lines, write, print, copy, and delete text files.

Uploaded by

pilot250504
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming 2

Tutorial 10
Exercise 1 (required)

Build a utility library XFile with read() and write() functions allowing reading and writing
binary files. Utilize the above library to copy one file to another.

GUIDELINES:

Create the XFile class


Write code for the read() function

Write code for the write() function

Create the XFileDemo class containing the main() method and utilize the XFile library
as follows:

Exercise 2 (required)

Extend the XFile library with two functions allowing reading and writing objects from/to a
file.
Write code for the readObject() function

Write code for the writeObject() function

Utilize the readObject() and writeObject() functions to read and write


List<Student>. Note that the Student class must implement the Serializable
interface.
In the main method:

Exercise 3 (required)

Realize a Java class Matrix to represent bidimensional matrices of real numbers. The class
should export the following methods:

Matrix(int n, int m) : constructor that creates a matrix of size n × m, with all values
initially set to 0;
void save(String filename) : that saves the content of the matrix on the file
specified by filename;
static Matrix read(String filename) : that reads the data about a matrix from
the file specified by filename, creates the matrix, and returns it;
Matrix sum(Matrix m) : that returns the matrix that is the sum of the object and of m,
if the two matrices have the same dimensions, and null otherwise;
Matrix product(Matrix m) : that returns the matrix that is the product of the object
and of m, if the two matrices have compatible dimensions, and null otherwise.

Exercise 4 (required)

Realize a class IOFile that exports some functionalities on text files. The class should have a
constructor with one parameter of type String, representing the name of the file on which to
operate, and should export the following methods:

int countLines() : that returns the number of lines of the file;


void write(OutputStream os) : that writes the content of the file to os;
void print() : that prints the content of the file to the video;
void copy(String filename) : that copies the content of the file to the file specified
by filename;
void delete() : that deletes the file from storage.

You might also like