Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Product implements Comparable<Product>{
- private String name;
- private double price;
- public Product(String name, double price){
- this.name = name;
- this.price = price;
- }
- public String getName(){
- return name;
- }
- public double getPrice(){
- return price;
- }
- public int compareTo(Product compareFruit) {
- double otherPrice = ((Product) compareFruit).getPrice();
- //ascending order
- if(this.price>otherPrice) return 1;
- else
- if(this.price==otherPrice) return 0;
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement