next up previous
Up: Unit 09 Previous: Car sales: solution

Exercises

Exercise 09.1 Write a class IOStrings containing two public static methods:

Exercise 09.2 Write a public static method that reads from the keyboard a sequence of positive integers until the value 0 is inserted, and returns a double representing the average of the read values (without considering the final 0).

Exercise 09.3 Write a public static method that prints on the video all lines of a file that start with one of the characters '/', ';', or '%'. The name of the file should be given as a parameter.

Exercise 09.4 Write a public static method that takes as parameters a string representing a filename and an integer n, and writes on the file the multiplication table of size n. For example, for n = 3, the method should write:

1  2  3
2  4  6
3  6  9

Exercise 09.5 Write a public static method that reads from a file information about exam marks obtained by students, organized as follows:

Rossi 25 24 26 30 24 30
Bianchi 20 24 25
Verdi 30 24 30 27
The method should return a string representing the name of the student with the highest average marking.

Exercise 09.6 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:

Exercise 09.7 Realize a class HandleBAs to handle a set of bank accounts, represented as in Units 4 and 5. The data for the bank accounts are stored on a text file according to the following format:

name
surname
balance

The class HandleBAs should export the following methods:

Exercise 09.8 Add to the class Apartment of Exercise 7.12 a public method saveToFile that takes as a parameter a filename and saves the data about the apartment to the file. Add also a public static method readFromFile that takes as a parameter a BufferedReader object specifying an input channel, reads from the channel the data about an apartment (organized as written by saveToFile), and constructs and returns the apartment. Then, write a static method, client of the class Apartment, that takes as parameter a filename and prints on the video all the information about the apartments on the file.

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


next up previous
Up: Unit 09 Previous: Car sales: solution