Last active
August 29, 2015 13:56
-
-
Save d8ta/9131324 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| interface IPrintAll | |
| { | |
| void print(); | |
| } | |
| interface IChangeData | |
| { | |
| void daten(); | |
| } | |
| class Article : IPrintAll, IChangeData | |
| { | |
| protected uint artikelnummer; | |
| protected string name; | |
| protected double preis; | |
| public Article() | |
| { | |
| artikelnummer = 000; | |
| name = null; | |
| preis = 0.00; | |
| } | |
| public Article(uint artikelnummer, string name, double preis) | |
| { | |
| this.artikelnummer = artikelnummer; | |
| this.name = name; | |
| this.preis = preis; | |
| } | |
| // Virituelle Printmethode | |
| public virtual void print() | |
| { | |
| Console.WriteLine (artikelnummer + " \\ " + name + " \\ " + preis + " €"); | |
| } | |
| // a) Preis und Name verändern | |
| public void daten() | |
| { | |
| Console.WriteLine ("Möchten Sie Daten verändern? (1) für Name und (2) für Preis:"); | |
| string userInputYesNo = Console.ReadLine (); | |
| int userNumYesNo = int.Parse (userInputYesNo); | |
| if (userNumYesNo == 1) { | |
| Console.WriteLine ("Geben Sie den neuen Namen ein: "); | |
| this.name = Console.ReadLine (); | |
| } else { | |
| Console.WriteLine ("Geben Sie den neuen Preis ein: "); | |
| string neuerPreis = Console.ReadLine (); | |
| double neuerIntPreis = double.Parse (neuerPreis); | |
| this.preis = neuerIntPreis; | |
| } | |
| } | |
| // b) Steuerprozente zuschlagen | |
| public double addTax (float p) | |
| { | |
| this.preis = this.preis * (1 + (p / 100)); | |
| return this.preis; | |
| } | |
| } | |
| // d) Unterklassen generieren und base nutzen | |
| class Book : Article | |
| { | |
| protected string autor; | |
| protected uint jahr; | |
| public Book () : base () | |
| { | |
| autor = null; | |
| jahr = 1900; | |
| } | |
| public Book (string autor, uint jahr) : base(artikelnummer, name, preis) // Hier bekomme ich die Fehlermeldung! | |
| { // mit dem base(......) möchte ich die Attribute | |
| this.autor = autor; // des Konstruktors der Klasse "Article" nutzen. | |
| this.jahr = jahr; | |
| } | |
| // für Book-Klasse | |
| public override void print() | |
| { | |
| Console.WriteLine (artikelnummer + " \\ " + name + " \\ " + preis + " €" + " \\ " + autor + " \\ " + jahr); | |
| } | |
| } | |
| class Programm | |
| { | |
| public static void Main() | |
| { | |
| // Article Article1 = new Article (001, "Butter", 2.99); | |
| // Article Article2 = new Article (002, "Kaffee", 5.99); | |
| // Article Article3 = new Article (); | |
| // Article Article4 = new Article (003, "iPad", 379.99); | |
| // | |
| // Article1.print (); | |
| // Article1.addTax (19); | |
| // Article1.print (); | |
| Book Buch1 = new Book (); | |
| Book Buch2 = new Book ("Daniel", 1979); | |
| Buch2.print (); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment