Task 1. 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 ofString
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 a telephone.
Create a non-abstract class called MobilePhone
which is a subclass of Telephone
class. The constructor of MobilePhone
class initializes the name of an 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 an 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 a 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 information about each telephone.