Advertisement
niske

Voce - Ostale klase

Dec 2nd, 2024 (edited)
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | Source Code | 0 0
  1. public class Voce implements Comparable<Voce>{
  2.     private String ime;
  3.     private double zapremina;
  4.    
  5.     public Voce(String ime, double zapremina) {
  6.         this.ime = ime;
  7.         this.zapremina = zapremina;
  8.     }
  9.  
  10.     public String getIme() {
  11.         return ime;
  12.     }
  13.  
  14.     public double getZapremina() {
  15.         return zapremina;
  16.     }
  17.  
  18.     @Override
  19.     public String toString() {
  20.         return "Voce [ime=" + ime + ", zapremina=" + zapremina + "]";
  21.     }
  22.  
  23.     @Override
  24.     public int compareTo(Voce o) {
  25.         return Double.compare(this.zapremina, o.getZapremina());
  26.     }
  27. }
  28.  
  29.  
  30. /-----------------------------------------------------------------------
  31.  
  32.  
  33. public class Jabuka extends Voce{
  34.     private boolean crvljivo;
  35.     public Jabuka(String ime, double zapremina, boolean crvljivo) {
  36.         super(ime, zapremina);
  37.         this.crvljivo = crvljivo;
  38.     }
  39.    
  40.     public boolean isCrvljivo() {
  41.         return crvljivo;
  42.     }
  43.    
  44. }
  45.  
  46. /-----------------------------------------------------------------------
  47.  
  48.  
  49.  
  50. public class Ananas extends Voce{
  51.  
  52.     public Ananas(String ime, double zapremina) {
  53.         super(ime, zapremina);
  54.         // TODO Auto-generated constructor stub
  55.     }
  56.    
  57.     @Override
  58.     public double getZapremina() {
  59.         return super.getZapremina() * 0.5;
  60.     }
  61. }
  62.  
  63.  
  64. /-----------------------------------------------------------------------
  65.  
  66.  
  67. public interface Kontejner {
  68.    
  69.     public double zapremina();
  70.    
  71.     public int komada();
  72.    
  73. }
  74.  
  75.  
  76.  
  77. /-----------------------------------------------------------------------
  78.  
  79.  
  80.  
  81. public interface Cediljka {
  82.     public void cedi();
  83. }
  84.  
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement