Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zjazd3;
- public abstract class Figura implements Obliczenie, Comparable<Figura>{
- protected int x, y; // położenie figury
- protected int FigNo;
- protected String fig = "Jeszcze nie wiadomo"; // nazwa figury z wartością początkową
- public Figura(int x, int y){ // konstruowanie figury na podstawie podanego położenia
- this.x = x;
- this.y = y;
- }
- public String toString(){ // podaje nazwę figury i położenie
- return fig;
- }
- public abstract void pozycja(int x, int y); // wypisuje komunikat, czy punkt (x, y) znajduje się wewnątrz figury
- @Override
- public int compareTo(Figura figura) {
- double pole1 = this.pole();
- double pole2 = figura.pole();
- double obwod1 = this.obwod();
- double obwod2 = figura.obwod();
- if(pole1 < pole2){
- return -1;
- }
- if(pole1 > pole2){
- return 1;
- }
- if(obwod1 > obwod2){
- return 1;
- }
- if(obwod1 < obwod2){
- return -1;
- }
- if(this.FigNo > figura.FigNo){
- return 1;
- }
- if(this.FigNo < figura.FigNo){
- return -1;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement