Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.88 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package laatikot;
  2.  
  3. import java.lang.Exception;
  4.  
  5. public class Tavara {
  6.  
  7.     private String nimi;
  8.     private int paino;
  9.  
  10.     public Tavara(String nimi, int paino) {
  11.  
  12.         this.nimi = nimi;
  13.         if (paino >= 0) {
  14.             this.paino = paino;
  15.         } else {
  16.  
  17.             throw new IllegalArgumentException();
  18.  
  19.         }
  20.     }
  21.  
  22.     public Tavara(String nimi) {
  23.         this(nimi, 0);
  24.     }
  25.  
  26.     public String getNimi() {
  27.         return nimi;
  28.     }
  29.  
  30.     public int getPaino() {
  31.         return paino;
  32.     }
  33.  
  34.     @Override
  35.     public int hashCode() {
  36.         int hash = 3;
  37.         hash = 97 * hash + (this.nimi != null ? this.nimi.hashCode() : 0);
  38.         return hash;
  39.     }
  40.  
  41.     @Override
  42.     public boolean equals(Object o) {
  43.  
  44.         if (o.equals(this.nimi)){
  45.             return true;
  46.         } else {
  47.             return false;
  48.         }
  49.     }
  50. }