Institute of Computer Science
  1. Courses
  2. 2017/18 spring
  3. Object-Oriented Programming (Narva College) (P2NC.01.083)
ET
Log in

Object-Oriented Programming (Narva College) 2017/18 spring

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

Tasks (to be submitted by Sun 18.03 23:55) 1 point

Task 1. Creativity

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 the tasks which:

  • require overriding,
  • dynamic binding,
  • polymorphism.

Add comments where overriding, dynamic binding 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

Create RadioListener class. Add void method listen which takes in one parameter (String) for the message to be broadcast; the method remembers the message into a list .RadioListener class also has recall method which returns all the messages that have been listened as a list of Strings.

Create RadioTransmitter class which is able to broadcast 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 the broadcast message as String argument and broadcasts it to all the listeners from the list (use listen method from RadioListener class).

Create a subclass of RadioTransmitter called BingoNumberInformer. Add raffleAndBroadcast method (without parameters ) which generates lucky numbers for the bingo game (10 numbers in the range between 1 and 100) and broadcasts the numbers to the listeners as one String message - 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 returns the message 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).

Create a subclass of RadioListener called CrazyListerner who remembers the broadcast messages chequer-wise (remembers the first message, the second does not, remembers the third message 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 listeners and some crazy listeners to them. Update the list of the news with your own news. Broadcast the news of BingoNumberInformer, ChooseRadioTransmitter and NewsRadio. Print the messages that each listener has listened to.

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