Guest User

Untitled

a guest
May 19th, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.  
  2. class Products implements Comparable<Products>{
  3.    
  4.     private String product;
  5.     private double price;
  6.    
  7.     public Products(String product, double price){
  8.         this.product = product;
  9.         this.price = price;
  10.     }
  11.    
  12.     public String getProduct(){
  13.         return product;
  14.     }
  15.    
  16.     public double getPrice(){
  17.         return price;
  18.     }
  19.    
  20.     public int compareTo(Products compareFruit) {
  21.        
  22.         double otherPrice = ((Products) compareFruit).getPrice();
  23.  
  24.         if(this.price > otherPrice){
  25.             return 1;
  26.         }
  27.         else if(this.price == otherPrice){
  28.             return 0;
  29.         }
  30.         else {
  31.             return -1;
  32.         }
  33.     }  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment