Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ProgrammierenÜbung9
- {
- class Product
- {
- protected int barcode;
- protected string bezeichnung;
- public Product(string _bezeichnung, int _barcode)
- {
- bezeichnung = _bezeichnung;
- barcode = _barcode;
- }
- public int Barcode
- {
- get { return barcode; }
- set { barcode = value; }
- }
- public string Bezeichnung
- {
- get { return bezeichnung; }
- set { bezeichnung = value; }
- }
- public string Print ()
- {
- string s = bezeichnung + " " + barcode;
- return s;
- }
- }
- class PackedFood : Product
- {
- protected double stpreis;
- public PackedFood(string bez, int bar, double _stpreis) : base(bez, bar)
- {
- stpreis = _stpreis;
- }
- public double Stpreis
- {
- set { stpreis = value; }
- }
- public string Print ()
- {
- string s = base.Print() + " " + stpreis;
- return s;
- }
- }
- class UnpackedFood: Product
- {
- protected double kpreis;
- protected double gewicht;
- public UnpackedFood(string bez, int bar, double _kpreis, double _gewicht) : base(bez, bar)
- {
- kpreis = _kpreis;
- gewicht = _gewicht;
- }
- public double Kpreis
- {
- set { kpreis = value; }
- }
- public string Print ()
- {
- double preis = kpreis / 1000 * gewicht;
- string s = base.Print() + preis;
- return s;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Product[] pa = new Product[4];
- pa[0] = new UnpackedFood("Apfel", 666, 10, 400);
- pa[1] = new UnpackedFood("Banane",222,50,2000);
- pa[2] = new PackedFood("Bohnen",111,2500);
- pa[3] = new PackedFood("Haasd", 519,30000);
- for (int i = 0; i < 4; i++ )
- {
- Console.WriteLine(pa[i].Print());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement