Klassen6

CSharp · Console

/Program.cs

using System;

public class Persoon
{

    public string Achternaam { get; set; }
    public string Voornaam { get; set; }     
	private DateTime _GeboorteDatum;

	public DateTime Geboortedatum
	{
		get { return _GeboorteDatum; }
		set
		{
			if (DateTime.Compare(value, DateTime.Today) != 1)
			{
				_GeboorteDatum = value;
			}
			else
			{
				throw new Exception("De geboortedatum mag niet in de toekomst liggen!");
			}
		}
	}
	
	
	public Persoon()
	{
		Achternaam = "";
		Voornaam = "";
		Geboortedatum = DateTime.Today;
	}
	
	public Persoon(string Achter, string Voor, DateTime Datum)
	{
		Achternaam = Achter;
		Voornaam = Voor;
		Geboortedatum = Datum;
	}
	
	public override string ToString()
	{
	   return Voornaam + " " + Achternaam + " - " + Geboortedatum.ToShortDateString();
	}
	
	public string Naam(){
		return Achternaam + " " + Voornaam;	
	}
}


public class Cursist: Persoon
{
	private int _Cursistnummer;
	public int Cursistnummer
	{
		get { return _Cursistnummer; }
		set
		{
			if (value >= 0)
			{
				_Cursistnummer = value;
			}
			else
			{
				throw new Exception("Geef een positieve waarde in voor het cursistnummer!");
			}
		}
	}
	
	public Cursist()
	{
		Cursistnummer = 0;

	}
	
	public Cursist(int Nummer, string Achter, string Voor, DateTime Datum)
	{
		Cursistnummer = Nummer;
		Achternaam = Achter;
		Voornaam = Voor;
		Geboortedatum = Datum;
	}

	
	public override string ToString()
	{
	   return Cursistnummer + ": " + Voornaam + " " + Achternaam + " - " + Geboortedatum.ToShortDateString();
	}

}

					
public class Program
{
	public static void Main()
	{
		try{
			Cursist Ik = new Cursist(1, "Linthoudt", "Geert", new DateTime(1969,10,1));
					
			Console.WriteLine(Ik.Naam());
			Console.WriteLine(Ik.ToString());
			
		}
		catch(Exception ex)
		{
			Console.WriteLine(ex.Message);
		}
	}
}
;