Arvutiteaduse instituut
  1. Kursused
  2. 2019/20 kevad
  3. Objektorienteeritud programmeerimine (Narva Kolledž) (LTAT.NR.003)
EN
Logi sisse

Objektorienteeritud programmeerimine (Narva Kolledž) 2019/20 kevad

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

Tasks (to be submitted by 27.04)

Task 1

Use Map to solve the following task. Write a program which reads the data in from a file, makes statistics on the used words and displays the result on the screen. (Hint: if a word already exists in the map, replace its value.)

The program should have a class called TextAnalyzer. In the class, there should be two constructors: one takes in the file name as an argument; the second constructor should take in two parameters - java.io.File (from where to read data in) and String (for the file encoding). The result of the analysis should be returned by a method without parameters called wordFrequency.

Hint: it is possible to get some text from a file using only one expression. The required components are:

  • java.nio.Files#readAllBytes
  • java.io.File#toPath
  • java.lang.String(byte[], String)

Task 2

Create a class called Pair which has two parameter types. The class has two instance fields (one for each type), a constructor which instantiates the fields and the get and set methods (getFirst, getSecond, setFirst, setSecond). Add toString method which returns the content of the fields. Create a client class. In the main method of the class, create a pair of String,Integer (e.g. a person's name and his age) and a pair of String,String (e.g. a person's name and his address) and test the instance methods.

Task 3

Create a generic class called Comparer which takes in one parameter type. Bind the parameter type so that it can take only types that implement the Comparable interface. Add a method called findLargest which takes two parameters. The method has to compare the objects and return the largest object based on the compareTo method.

Hint: <T extends Comparable<T>> is a good start - T is the data type whose objects can be compared.

Chapter 12
  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused