Advertisement
jaVer404

level17.lesson10.home02

Sep 28th, 2015
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1. package com.javarush.test.level17.lesson10.home02;
  2.  
  3. /* Comparable
  4. Реализуйте интерфейс Comparable<Beach> в классе Beach, который будет использоваться нитями.
  5. */
  6.  
  7. public class Beach implements Comparable<Beach>
  8.  
  9. {
  10.     private String name;      //название
  11.     private float distance;   //расстояние
  12.     private int quality;    //качество
  13.  
  14.     public Beach(String name, float distance, int quality) {
  15.         this.name = name;
  16.         this.distance = distance;
  17.         this.quality = quality;
  18.     }
  19.  
  20.     public synchronized String getName() {
  21.         return name;
  22.     }
  23.  
  24.     public synchronized void setName(String name) {
  25.         this.name = name;
  26.     }
  27.  
  28.     public synchronized float getDistance() {
  29.         return distance;
  30.     }
  31.  
  32.     public synchronized void setDistance(float distance) {
  33.         this.distance = distance;
  34.     }
  35.  
  36.     public synchronized int getQuality() {
  37.         return quality;
  38.     }
  39.  
  40.     public synchronized void setQuality(int quality) {
  41.         this.quality = quality;
  42.     }
  43.  
  44.     @Override
  45.     public synchronized int compareTo(Beach o)
  46.     {
  47.         return (int) ((this.quality*1000000)/this.distance- (o.quality*1000000)/o.distance);
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement