Skip to content
Snippets Groups Projects
Commit 43665896 authored by Uwe Wienkop's avatar Uwe Wienkop
Browse files

2020-04-20

parent 334c9196
Branches
No related tags found
No related merge requests found
Showing
with 77 additions and 11 deletions
......@@ -10,7 +10,7 @@
// Dieses Property muss vor dem Anlegen der ersten Person aufrufbar sein!
// - Property: Zum Lesen des Namens (kann auch als Auto-Property realisiert werden)
// - Überladene ToString-Methode: Soll den Namen und die Id ausgeben
#region Bürgeramt
// Programmieren Sie zusätzlich eine Klasse Bürgeramt mit folgenden Eigenschaften
// string ort
// - Konstruktor, dem der Ortsname und die Anzahl der zu speichernden Personalausweise übergeben werden
......@@ -21,15 +21,65 @@
// Main: Legen Sie zwei Bürgerämter an (Nürnberg/Fürth) und lassen Sie für Nürnberg mehrere Pässe erzeugen
// Optional: Rufen Sie AllePersos mit einem passenden Teilnamen auf und geben Sie diese aus!
#endregion
namespace _01Buergeramt
{
class Personalausweis
{
public string name { get; private set; }
int id;
static int naechsteId=1000;
public Personalausweis(string name)
{
this.name = name;
id = naechsteId++;
}
public static int NaechsteId {
get => naechsteId;
set
{
if (value >= naechsteId)
naechsteId = value;
else
throw new ArgumentOutOfRangeException("Wert muss größer als ... sein");
}
}
public override string ToString() => $"Name: {name} Id: {id}";
}
class Buergeramt
{
string ort;
int anzPersonalausweise;
Personalausweis[] ausweise;
int aktAnz = 0;
public Buergeramt(string ort, int anzahlPersonalausweise)
{
this.ort = ort;
anzPersonalausweise = anzahlPersonalausweise;
ausweise = new Personalausweis[anzPersonalausweise];
}
public Personalausweis NeuerAusweis(string name)
{
Personalausweis p = new Personalausweis(name);
ausweise[aktAnz++] = p;
return p;
}
public Personalausweis NeuerAusweis(Personalausweis alterPerso)
{
ausweise[aktAnz++] = alterPerso;
return alterPerso;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Personalausweis p1 = new Personalausweis("Anton");
Console.WriteLine(p1);
}
}
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -11,13 +11,14 @@ namespace _01KlassenWiederholung
// Legt eine anonyme Variable an ~alter4711
// plus eine öffentliche get-Methode plus eine private set-Methode
private string telNr;
private readonly int steuerIdentNummer;
private readonly int steuerIdentNummer=100;
// readonly = Diese Variable darf nur im Konstruktor geändert werden
//private DateTime gebDatum;
// static Member/static Datenfelder (MIT Angabe von static)
// Kommen nur einmal pro Klasse vor
private static int naechsteIdentnummer = 1;
private static int naechsteIdentnummer = 0;
private static Person[] personen = new Person[1000];
// get ~ gezielte Umgehung des private-Schutzes; liefert Wert zurück
......@@ -60,16 +61,26 @@ namespace _01KlassenWiederholung
public int Alter4 { get; private set; }
// Öffentliches get, privates set
static Person()
{
Console.WriteLine("Statischer Konstruktor");
naechsteIdentnummer = 100;
}x
public Person(int stId)
{
steuerIdentNummer = stId;
}
// Konstruktor Person
public Person(string Name, string Vorname, int Alter, string TelNr = "")
public Person(string name, string Vorname, int Alter, string TelNr = "")
{
name = Name;
this.name = name;
vorname = Vorname;
if (Alter < 0)
throw new ArgumentOutOfRangeException("Das Alter muss >= 0 sein");
Alter2 = Alter;
telNr = TelNr;
steuerIdentNummer = naechsteIdentnummer;
personen[naechsteIdentnummer] = this;
naechsteIdentnummer++;
}
// STATIC oder NICHT-STATIC???
......@@ -131,8 +142,10 @@ namespace _01KlassenWiederholung
static void Main(string[] args)
{
Console.WriteLine("Programmstart");
// anton.SetzeIdentnummer(1000000); -- geht nicht, da anton noch nicht existiert
Person.SetzeIdentnummer(1000000);
Console.WriteLine("Hier sind wir ...");
Person anton = new Person("Müller", "Anton", 23);
anton.setAlter(24);
anton.setAlter(anton.getAlter() + 1);
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -12,14 +12,17 @@ namespace _01OperatorOverloading
throw new ArgumentNullException("Nenner darf nicht 0 sein!");
n = N;
}
//public static explicit operator int(Bruch b1) => 1;
public static implicit operator int(Bruch b1) => 1;
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Bruch b1 = new Bruch(1, 3);
int k = b1;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment