SHARE
TWEET

lab 6

Mary_99 Apr 3rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.TreeMap; // sorting implementation
  2.  
  3. class lab6
  4. {
  5.     public static void main(String[] args){
  6.     TelephoneEntry person = new Person("Jan", "Nowak", "Mickiewicza33", new TelephoneNumber(48, 345676543));
  7.     TelephoneEntry company = new Company("CHanel", "Piotrkowska 7", new TelephoneNumber(48, 444788665));
  8.     TreeMap<TelephoneNumber, TelephoneEntry> telephones = new TreeMap<>();
  9.     telephones.put(person.getTelephoneNumber(), person);
  10.     telephones.put(company.getTelephoneNumber(), company);
  11.     }
  12. }
  13. class TelephoneNumber implements Comparable <TelephoneNumber>
  14.  {
  15.     Integer countryCode;
  16.     Integer localNumber;
  17.     public TelephoneNumber(int countryCode, int localNumber)
  18.     {
  19.         this.countryCode = countryCode;
  20.         this.localNumber = localNumber;
  21.     }
  22.  
  23.     public int compareTo(TelephoneNumber telephoneNumber)
  24.     {
  25.       return this.localNumber.compareTo(telephoneNumber.localNumber);
  26.     }
  27. }
  28.  
  29. abstract class TelephoneEntry
  30. {
  31.     abstract public void description();
  32.     abstract public TelephoneNumber getTelephoneNumber();
  33.     abstract public String getName();
  34.  
  35. }
  36.  
  37. class Person extends TelephoneEntry
  38. {
  39.     String name;
  40.     String lastname;
  41.     String adress;
  42.     TelephoneNumber telephoneNumber;
  43.  
  44.     public Person(String name, String lastname, String adress, TelephoneNumber telephoneNumber)
  45.     {
  46.         this.name = name;
  47.         this.lastname = lastname;
  48.         this.adress = adress;
  49.         this.telephoneNumber = telephoneNumber;
  50.    }
  51.  
  52.     public void description(){}
  53.  
  54.     public TelephoneNumber getTelephoneNumber()
  55.     {
  56.         return telephoneNumber;
  57.     }
  58.  
  59.     public String getName()
  60.     {
  61.         return name;
  62.     }
  63.  
  64. }
  65.  
  66. class Company extends TelephoneEntry
  67. {
  68.     String name;
  69.     String adress;
  70.     TelephoneNumber telephoneNumber;
  71.  
  72.     public Company(String name, String adress, TelephoneNumber telephoneNumber)
  73.     {
  74.         this.name = name;
  75.         this.adress = adress;
  76.         this.telephoneNumber = telephoneNumber;
  77.  
  78.     }
  79.  
  80.     public void description(){}
  81.  
  82.     public TelephoneNumber getTelephoneNumber()
  83.     {
  84.         return telephoneNumber;
  85.     }
  86.  
  87.     public String getName()
  88.     {
  89.         return name;
  90.     }
  91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top