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

Task 1. Telephone

Create an abstract class called Telephone which has private instance fields for the 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 instantiates 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 subclass of Telephone class. The constructor of DeskTelephone class instantiated 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 subclass of Telephone class. The constructor of MobilePhone class instantiated 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.

Update 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. Output information about each telephone.

Create the main class. Create an array of different telephones and sort the array using java.util.Arrays.sort(Object[] o) method.

  • 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