Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ProgrammierenÜbung9
  8. {
  9.     class Product
  10.     {
  11.         protected int barcode;
  12.         protected string bezeichnung;
  13.  
  14.  
  15.         public Product(string _bezeichnung, int _barcode)
  16.         {
  17.             bezeichnung = _bezeichnung;
  18.             barcode = _barcode;
  19.         }
  20.  
  21.         public int Barcode
  22.         {
  23.             get { return barcode; }
  24.             set { barcode = value; }
  25.         }
  26.         public string Bezeichnung
  27.         {
  28.             get { return bezeichnung; }
  29.             set { bezeichnung = value; }
  30.         }
  31.  
  32.         public string Print ()
  33.         {
  34.             string s = bezeichnung + " " + barcode;
  35.             return s;
  36.         }
  37.  
  38.  
  39.     }  
  40.     class PackedFood : Product
  41.     {
  42.         protected double stpreis;
  43.  
  44.         public PackedFood(string bez, int bar, double _stpreis) : base(bez, bar)
  45.         {
  46.             stpreis = _stpreis;
  47.         }        
  48.          
  49.         public double Stpreis
  50.         {
  51.             set { stpreis = value; }
  52.         }
  53.         public string Print ()
  54.         {
  55.             string s = base.Print() + " " + stpreis;
  56.             return s;
  57.         }
  58.     }
  59.  
  60.  
  61.  
  62.     class UnpackedFood: Product
  63.     {
  64.         protected double kpreis;
  65.         protected double gewicht;
  66.  
  67.         public UnpackedFood(string bez, int bar, double _kpreis, double _gewicht) : base(bez, bar)
  68.         {
  69.             kpreis = _kpreis;
  70.             gewicht = _gewicht;
  71.         }
  72.         public double Kpreis
  73.         {
  74.             set { kpreis = value; }
  75.         }
  76.  
  77.         public string Print ()
  78.         {
  79.             double preis = kpreis / 1000 * gewicht;
  80.             string s = base.Print() + preis;
  81.             return s;
  82.         }
  83.     }
  84.  
  85.     class Program
  86.     {      
  87.         static void Main(string[] args)
  88.         {
  89.             Product[] pa = new Product[4];
  90.             pa[0] = new UnpackedFood("Apfel", 666, 10, 400);
  91.             pa[1] = new UnpackedFood("Banane",222,50,2000);
  92.             pa[2] = new PackedFood("Bohnen",111,2500);
  93.             pa[3] = new PackedFood("Haasd", 519,30000);
  94.  
  95.             for (int i = 0; i < 4; i++ )
  96.             {
  97.                 Console.WriteLine(pa[i].Print());
  98.             }
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement