Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AllInOne
- {
- public static void main(String[] args)
- {
- Produkt p1 = new Produkt(14, 4.15);
- Produkt p2 = new Produkt(7,20.14);
- Werk w1 = new Werk(p1);
- Werk w2 = new Werk(p2);
- Firma f1 = new Firma(w1, w2);
- System.out.println(String.format("%.2fâŹ", f1.berechneGesamtUmsatz()));
- }
- }
- class Firma
- {
- private Werk w1;
- private Werk w2;
- public Firma(Werk w1, Werk w2)
- {
- this.w1 = w1;
- this.w2 = w2;
- }
- public double berechneGesamtUmsatz()
- {
- return w1.berechneUmsatz() + w2.berechneUmsatz();
- }
- }
- class Werk
- {
- private Produkt p;
- public Werk(Produkt p)
- {
- this.p = p;
- }
- public double berechneUmsatz()
- {
- return p.holePreis() * p.holeAnzahl();
- }
- }
- class Produkt
- {
- private double preis;
- private int anzahlVerkauft;
- Produkt(int anzahlVerkauft, double preis)
- {
- this.anzahlVerkauft = anzahlVerkauft;
- this.preis = preis;
- }
- public double holePreis()
- {
- return preis;
- }
- public int holeAnzahl()
- {
- return anzahlVerkauft;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement