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

Object-Oriented Programming (Narva College) 2018/19 spring

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

Tasks (to be submitted by Wed 13.03 12:55) 1 point

Task 1. Creativity (0.3 points)

Create at least 5 classes which are set in the tree hierarchy. Some topics for implementations are: geometric shapes, animals, sport, food, etc. Make up and solve tasks which require:

  • overriding
  • polymorphism

Add comments where overriding and polymorphism are used. In MS Paint or any other editor, draw the inheritance tree (class hierarchy). The tree must also contain Object class.

Task 2. Radio listener (0.7 points)

Create Radio class which represents a radio listener. Add void method listen which takes in one parameter (String) for a program to be played; the method also has to remember the program (in other words, the program has to be added into a list). Radio class also has recall method which returns all the programs that a particular Radio has played (the method has to return a list of String).

Create RadioTransmitter class which is able to broadcast programs to different listeners. At first, the list of listeners is empty. To remember a new listener, the class should have addListener method which remembers the listener given as an argument. The class also has broadcast method which takes in a program as a String argument and broadcasts it to all the listeners from the list (use listen method from Radio class).

Create a subclass of RadioTransmitter called BingoNumberInformer. Add raffleAndBroadcast method (without parameters) which generates lucky numbers for a bingo game (10 numbers in the range between 1 and 100 inclusive) and broadcasts the numbers to the listeners in a String message as a program - the numbers should be delimited by a space (Hint: use broadcast method from RadioTransmitter class).

Create a subclass of RadioTransmitter called LoudRadioTransmitter. The class should have a method with a parameter called broadcast (use overriding). The method broadcasts the program given as an argument in capital letters.

Create a subclass of RadioTransmitter called NewsRadio. The class should have a method with the following signature: void updateNews(ArrayList<String> news). The method is used to mark the most important news (Hint: all incoming news are important). To broadcast the news, the class should have a method without parameters called broadcastNews (Hint: use broadcast method from RadioTransmitter class to broadcast each piece of news as a separate program).

Create a subclass of Radio called CrazyRadio who remembers the programs chequer-wise (remembers the first program, the second does not, remembers the third program and so on). This method should call listen method from its parent class.

Create the main class which has instances of the classes: BingoNumberInformer, LoudRadioTransmitter and NewsRadio and bind some normal radios (listeners) and some crazy radios (listeners) to them. Update the list of the news with your own news. Broadcast the news of BingoNumberInformer, ChooseRadioTransmitter and NewsRadio. Print the programs that each radio (listener) has played.

Session 5
  • 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