Advertisement
Guest User

product

a guest
Jun 18th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. package com.alma.alt.Objects;
  2.  
  3. /**
  4.  * Created by alt on 17/06/2018.
  5.  */
  6.  
  7.  
  8. public class Product implements  Comparable<Product> {
  9.  
  10.     private String name;
  11.     private double price;
  12.     private double weight;
  13.     private Type type;
  14.  
  15.  
  16.     public Product(String name, double price, double weight, Type type) {
  17.         this.name = name;
  18.         this.price = price;
  19.         this.type = type;
  20.         this.weight = weight;
  21.     }
  22.  
  23.     public String getName() {
  24.         return name;
  25.     }
  26.  
  27.     public void setName(String name) {
  28.         this.name = name;
  29.     }
  30.  
  31.     public double getPrice() {
  32.         return price;
  33.     }
  34.  
  35.     public void setPrice(double price) {
  36.         this.price = price;
  37.     }
  38.  
  39.     public Type getType() {
  40.         return type;
  41.     }
  42.  
  43.     public void setType(Type type) {
  44.         this.type = type;
  45.     }
  46.  
  47.     public double getWeight() {
  48.         return weight;
  49.     }
  50.  
  51.     public void setWeight(double weight) {
  52.         this.weight = weight;
  53.     }
  54.  
  55.  
  56.     @Override
  57.     public int compareTo(Product p) {
  58.         double lastCmp = this.price.compareTo(p.getPrice());
  59.         return (lastCmp != 0 ? lastCmp : this.price.compareTo(p.getPrice()));
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement