Institute of Computer Science
  1. Courses
  2. 2019/20 spring
  3. Object-Oriented Programming (Narva College) (LTAT.NR.003)
ET
Log in

Object-Oriented Programming (Narva College) 2019/20 spring

  • Home
  • Materials
  • Grading
  • Java Glossary
  • Cheat sheet (S1-S6)
  • Source Example
  • Links
Chapter 13

Tasks (to be submitted by 4.05)

Task 1

Create a class called IDRegister. The class should contain List<String> which holds personal identification numbers and the method register which adds a personal identification number to the list if it is not there yet. In addition, the program has to implement index method that returns the index of a personal identification number in the list or -1 if the personal identification number is not registered. Use synchronization so that the registry list is protected against the race. Use the list as a monitor.

Create the client class to demonstrate the work of threads.

Task 2

Create several text files with a large number of numbers separated by spaces. Write a program that reads the numbers from the file and finds the sum of the numbers in each file. In the main class, create a queue into which you can add the calculated sums, and a queue in which the names of the files waiting to be processed are stored. In the main method, the names of all the files should be placed into the queue for the filenames and three threads should start their work. Each thread should take a file from the queue with the filenames, read the numbers in, find the sum of the numbers and put the sum to the queue with the results. Once the file has been processed, the thread has to attempt to take the next file from the queue and process it, etc. The main method should take and display as many numbers from the result queue as there are files.

Chapter 13
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment