string msg;
ArrayList results = null;
try
{
results = new ArrayList()
{new Result(444444, 3.0), new Result(555555, 1.0),
new Result(666666, 3.3)};
}
catch (Exception e)
{
msg = e.Message;
}
for (int i = 0; i < results.Count; i++)
{
Console.Write("{0}\t", ((Result)results[i]).Matrikel);
Console.Write("{0,5:f1}\n", ((Result)results[i]).Note);
}
double sum = 0, average;
for (int i = 0; i < results.Count; i++)
sum += ((Result)results[i]).Note;
average = sum / results.Count;
Console.WriteLine("\nnumber of participants: {0,5}", results.Count);
Console.WriteLine("average grade : {0,5:f2}", average);
}
class Result
{
private int matrikel;
public int Matrikel
{
set
{
if (value < 100000 | value > 999999)
throw new Exception ("Matrikelnummer muss zwischen 100000 und 999999 liegen");
else matrikel = value;
}
get { return matrikel; }
}
private double note;
public double Note
{
set
{
if (value < 1.0 | value > 5.0)
throw new Exception ("Note muss zwischen 1,0 und 5,0 liegen");
else note = value;
}
get { return note; }
}
public Result(int matrikel, double note)
{
Matrikel = matrikel;
Note = note;
}
}