Знаю, код выглядит монструозно. Пробовала и другими способами , но валидатору не угодить по 3 пункту
package com.javarush.task.task17.task1714;
/*
Comparable
*/
public class Beach implements Comparable<Beach> {
private String name; //название
private float distance; //расстояние
private int quality; //качество
public Beach(String name, float distance, int quality) {
this.name = name;
this.distance = distance;
this.quality = quality;
}
public synchronized String getName() {
return name;
}
public synchronized void setName(String name) {
this.name = name;
}
public synchronized float getDistance() {
return distance;
}
public synchronized void setDistance(float distance) {
this.distance = distance;
}
public synchronized int getQuality() {
return quality;
}
public synchronized void setQuality(int quality) {
this.quality = quality;
}
public static void main(String[] args) {
Beach beach1 = new Beach("Monika", 7.6f, 6);
Beach beach2 = new Beach("Maiami", 5.6f, 7);
int rez = beach1.compareTo(beach2);
System.out.println(rez);
}
@Override
public synchronized int compareTo(Beach o) {
int counter = 0;
if (this.getQuality() > o.getQuality()) {
counter++;
}
if (this.getQuality() < o.getQuality()) {
counter--;
}
if (this.getDistance() > o.getDistance()) {
counter++;
}
if (this.getDistance() < o.getDistance()) {
counter--;
}
if (counter> 0){return 1;}
if (counter< 0){return -1;}
else return 0;
}
}