Arvutiteaduse instituut
  1. Kursused
  2. 2017/18 kevad
  3. Objektorienteeritud programmeerimine (Narva Kolledž) (P2NC.01.083)
EN
Logi sisse

Objektorienteeritud programmeerimine (Narva Kolledž) 2017/18 kevad

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