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

Task 1. Upgrade the TextAnalyzer

Modify the first task of the home assignment as follows. Add a method without parameters called wordSequences. The method has to return info about word sequences in an appropriate data structure. For example, if the text to analyze is "A bird in the hand is worth two in the bush", then the program output should be:

 {a={bird=1}, bird={in=1}, in={the=2}, the={hand=1, bush=1}, hand={is=1}, is={worth=1}, worth={two=1}, two={in=1}, hand={is=1}, bush={}}

Hint: an appropriate data structure for the task is most probably Map<String, Map<String, Integer>>.

Task 2. Birthday party

A student wants to celebrate his birthday and organizes a memorable birthday party. The student has asked each of his friends to bring another friend along to the party. As a result, many people have come to the party: birthday boy's friends, the friends of the friends and so on. In the following file, there are two names on each line: inviter's name and his friend's name (each name consists of one word, the names are separated by a space).

A sample file with guests:

 Martin Kelly
 Herbert Jack
 Kelly Paul
 Jack Mark
 Paul Jane

Write a program into a class called BirthdayParty. The main method of the client class takes in two parameters from the command line: the name of a file and the name of a guest. The program has to find and print out the name of the initial guest (birthday's boy's friend). You can assume that the file is always written using the UTF-8 encoding.

An example of the program execution:

 > java BirthdayParty guest.txt Jane
 Martin

The output of the program is Martin because Jane is invited by Paul, Paul is invited by Kelly, and Kelly is invited by Martin. Martin is at the top of the inviters list for Jane.

Hint: first of all, read the data into a map. Think about how to organize the map. Is the first name of the line a key or a value?

  • 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