Advertisement
tr00per92

Product Class

May 17th, 2014
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1. public class Product implements Comparable<Product> {
  2.     private String name;
  3.     private double price;
  4.     public Product(String name, double price) {
  5.         this.name = name;
  6.         this.price = price;
  7.     }
  8.     public String getName() {
  9.         return name;
  10.     }
  11.     public void setName(String name) {
  12.         this.name = name;
  13.     }
  14.     public double getPrice() {
  15.         return price;
  16.     }
  17.     public void setPrice(double price) {
  18.         this.price = price;
  19.     }
  20.     @Override
  21.     public int compareTo(Product prod) {
  22.         if (this.price > prod.getPrice()) {
  23.             return 1;
  24.         }
  25.         else if (this.price < prod.getPrice()) {
  26.             return -1;
  27.         }
  28.         return 0;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement