Advertisement
zsoltizbekk

beugro

Jun 12th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. package vizsga_teszt;
  2.  
  3. class Ital {
  4.     protected double mennyiség;
  5.     protected boolean alkoholmentes;
  6.     public Ital(double mennyiség, boolean alkoholmentes) {
  7.         this.mennyiség = mennyiség;
  8.         this.alkoholmentes = alkoholmentes;
  9.         //System.out.println("2");
  10.         System.out.println("Új ital: " + this);
  11.     }
  12.    
  13.     public Ital(double mennyiség) {
  14.         this(mennyiség, false);
  15.         //System.out.println("1");
  16.     }
  17.    
  18.     @Override
  19.     public String toString() {
  20.         return "valamilyen ital ( " + mennyiség + " dl [" + (alkoholmentes ? "alkoholmentes" : "alkoholos") + "] )";
  21.     }
  22.    
  23.     public Ital kever(Ital i) {
  24.     boolean alkMent = alkoholmentes && i.alkoholmentes;
  25.     System.out.println("I + I: " + this + " + " + i);
  26.     return new Ital(mennyiség + i.mennyiség, alkMent);
  27.  
  28.     }
  29. }
  30.  
  31. class AlkoholMentes extends Ital {
  32.  
  33.     public AlkoholMentes(double mennyiség) {
  34.         super(mennyiség, true);
  35.         System.out.println("Új alkoholmentes ital: " + this);
  36.     }
  37.        
  38.     @Override
  39.     public String toString() {
  40.         return "mentes ital ( " + mennyiség + " dl [" + (alkoholmentes ? "alkoholmentes" : "alkoholos") + "] )";
  41.     }
  42.    
  43.     @Override
  44.     public Ital kever(Ital i) {
  45.         System.out.println("M + I: " + this + " + " + i);
  46.        
  47.         return new Ital(mennyiség + i.mennyiség, i.alkoholmentes);
  48.     }        
  49.    
  50.     public Ital kever(AlkoholMentes a) {
  51.     System.out.println("M + M: " + this + " + " + a);
  52.     return new AlkoholMentes(mennyiség + a.mennyiség);
  53.     }
  54. }
  55.  
  56. public class Vizsga_teszt {
  57.  
  58.     public static void main(String[] args) {
  59.        
  60.         Ital ii = new Ital(0.1);
  61.        
  62.         Ital mi = new AlkoholMentes(0.3);
  63.         AlkoholMentes mm = new AlkoholMentes(0.5);
  64.        
  65.         System.out.println("- - - - -");
  66.         System.out.println(ii.kever(ii));
  67.         System.out.println(ii.kever(mi));
  68.         System.out.println(ii.kever(mm));
  69.        
  70.         System.out.println("- - - - -");
  71.         System.out.println(mi.kever(ii));
  72.         System.out.println(mi.kever(mi));
  73.         System.out.println(mi.kever(mm));
  74.        
  75.         System.out.println("- - - - -");
  76.         System.out.println(mm.kever(ii));
  77.         System.out.println(mm.kever(mi));
  78.         System.out.println(mm.kever(mm));
  79.        
  80.         System.out.println("- - - - -");
  81.         System.out.println(((AlkoholMentes) mi).kever(ii));
  82.         System.out.println(((AlkoholMentes) mi).kever(mi));
  83.         System.out.println(((AlkoholMentes) mi).kever(mm));
  84.        
  85.         ii = mm;
  86.        
  87.         System.out.println("- - - - -");
  88.         System.out.println(ii.kever(ii));
  89.         System.out.println(ii.kever(mi));
  90.         System.out.println(ii.kever(mm));
  91.        
  92.         System.out.println("- - - - -");
  93.         System.out.println(mi.kever(mi).kever(mm).kever(new AlkoholMentes(0.5)));
  94.     }
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement