Advertisement
etlon

TwD20190224

Feb 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.08 KB | None | 0 0
  1.  
  2.  
  3. public class AllInOne
  4. {
  5.    
  6.     public static void main(String[] args)
  7.     {
  8.        
  9.         Produkt p1 = new Produkt(14, 4.15);
  10.         Produkt p2 = new Produkt(7,20.14);
  11.        
  12.         Werk w1 = new Werk(p1);
  13.         Werk w2 = new Werk(p2);
  14.         Firma f1 = new Firma(w1, w2);
  15.        
  16.         System.out.println(String.format("%.2f€", f1.berechneGesamtUmsatz()));
  17.        
  18.     }
  19.    
  20. }
  21.  
  22. class Firma
  23. {
  24.    
  25.     private Werk w1;
  26.     private Werk w2;
  27.    
  28.     public Firma(Werk w1, Werk w2)
  29.     {
  30.         this.w1 = w1;
  31.         this.w2 = w2;
  32.     }
  33.    
  34.     public double berechneGesamtUmsatz()
  35.     {
  36.         return w1.berechneUmsatz() + w2.berechneUmsatz();
  37.     }
  38.    
  39. }
  40.  
  41. class Werk
  42. {
  43.    
  44.     private Produkt p;
  45.    
  46.     public Werk(Produkt p)
  47.     {
  48.         this.p = p;
  49.     }
  50.    
  51.     public double berechneUmsatz()
  52.     {
  53.        
  54.         return p.holePreis() * p.holeAnzahl();
  55.     }
  56.    
  57. }
  58.  
  59. class Produkt
  60. {
  61.    
  62.     private double preis;
  63.     private int anzahlVerkauft;
  64.    
  65.     Produkt(int anzahlVerkauft, double preis)
  66.     {
  67.         this.anzahlVerkauft = anzahlVerkauft;
  68.         this.preis = preis;
  69.     }
  70.    
  71.     public double holePreis()
  72.     {
  73.         return preis;
  74.     }
  75.    
  76.     public int holeAnzahl()
  77.     {
  78.         return anzahlVerkauft;
  79.     }
  80.    
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement