Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package zjazd3;
  2.  
  3. public abstract class Figura implements Obliczenie, Comparable<Figura>{
  4.     protected int x, y;                             // położenie figury
  5.     protected int FigNo;
  6.     protected String fig = "Jeszcze nie wiadomo";   // nazwa figury z wartością początkową
  7.     public Figura(int x, int y){                    // konstruowanie figury na podstawie podanego położenia
  8.         this.x = x;
  9.         this.y = y;
  10.     }
  11.     public String toString(){                       // podaje nazwę figury i położenie
  12.         return fig;
  13.     }
  14.     public abstract void pozycja(int x, int y);     // wypisuje komunikat, czy punkt (x, y) znajduje się wewnątrz figury
  15.    
  16.     @Override
  17.     public int compareTo(Figura figura) {
  18.        
  19.         double pole1 = this.pole();
  20.         double pole2 = figura.pole();
  21.         double obwod1 = this.obwod();
  22.         double obwod2 = figura.obwod();
  23.        
  24.         if(pole1 < pole2){
  25.             return -1;
  26.         }
  27.         if(pole1 > pole2){
  28.             return 1;
  29.         }      
  30.         if(obwod1 > obwod2){
  31.             return 1;
  32.         }
  33.         if(obwod1 < obwod2){
  34.             return -1;
  35.         }
  36.         if(this.FigNo > figura.FigNo){
  37.             return 1;
  38.         }
  39.         if(this.FigNo < figura.FigNo){
  40.             return -1;
  41.         }
  42.         return 0;
  43.     }
  44.    
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement