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

Task. Telephone

Create an abstract class called Telephone which has private instance fields for a telephone number (String) and the buzz (String). The class has at least the following methods:

  • non-abstract get methods which return the values of the corresponding instance fields;
  • an abstract method called importantInfo which returns data of String type;
  • a constructor which initializes the instance fields;
  • a method with the following signature String lastNumbers(int n); the method returns n last digits of the telephone number.

Create a non-abstract class called DeskTelephone which is a subclass of Telephone class. The constructor of DeskTelephone class initializes the location (String) in addition to the telephone number and the buzz. The method importantInfo has to be overridden so that it returns the location of the telephone.

Create a non-abstract class called MobilePhone which is a subclass of Telephone class. The constructor of MobilePhone class initializes the name of the owner (String) and the functionality to take pictures (boolean) in addition to the telephone number and the buzz. The method importantInfo has to be overridden so that it returns the name of the owner.

Modify Telephone so that it implements Comparable<Telephone> interface. The comparison must be based on the last three digits of the telephone number (int).

Override toString method in DeskTelephone and MobilePhone classes so that all the information about the telephone would be printed out.

Create the main class. Create an array of different telephones, sort the array using java.util.Arrays.sort method and output the information about each telephone.

  • 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