Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Arvioinnit
- {
- public class Arviointi
- {
- private string opiskelijaNro;
- private readonly double[] koetulokset;
- private string arviontipvm = DateTime.Now.ToShortDateString();
- private short arvosana;
- public double I { get; set; }
- public double II { get; set; }
- public double III { get; set; }
- public double Koe { get; set; }
- public short Arvosana
- {
- get { return arvosana; }
- set
- {
- if ((value >= 0) && (value <= 5))
- {
- arvosana = value;
- }
- if ((value > 5) || (value < 0))
- {
- throw new ArgumentOutOfRangeException("Arvosana vain välillä [0,5]");
- }
- }
- }
- public string Arviointipvm
- {
- get { return arviontipvm; }
- set { arviontipvm = value; }
- }
- public string OpiskelijaNro
- {
- get { return opiskelijaNro; }
- set
- {
- if (opiskelijaNro.Length == 7)
- {
- if (Convert.ToInt32(opiskelijaNro.Substring(0, 2)) <= DateTime.Now.Year - 2000)
- {
- if (Koulutusalakoodit.IsKoulutusala(opiskelijaNro.Substring(2,2)))
- {
- if (Convert.ToInt32(opiskelijaNro.Substring(4, 3)) > 0)
- {
- opiskelijaNro = value;
- }
- }
- }
- }
- }
- }
- enum KOULUTUSALAT { TEKNIIKKA = 1, TALOUS, TERVEYS, TAIDE }
- public struct Koulutusalakoodit
- {
- KOULUTUSALAT ala;
- readonly string koodi;
- Koulutusalakoodit(KOULUTUSALAT kOULUTUSALAT)
- {
- ala = kOULUTUSALAT;
- koodi = string.Format("{0}{1}", 0, ala);
- }
- public static bool IsKoulutusala(string foo)
- {
- if ((foo.Length == 2) && (Enum.IsDefined(typeof(KOULUTUSALAT), Convert.ToInt16(foo))))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
- public class OpintojaksoArvioinnit : IStatistics
- {
- private double average;
- private double deviation;
- ObservableCollection<Arviointi> arvosanat = new ObservableCollection<Arviointi>();
- public short[] Numerot = new short[] { 0, 1, 2, 3, 4, 5 };
- public ObservableCollection<Arviointi> Arvosanat
- {
- get { return arvosanat; }
- set
- {
- if (arvosanat != null)
- {
- arvosanat = value;
- }
- else
- {
- throw new ArgumentNullException("Observations can not be null");
- }
- }
- }
- public double Keskiarvo()
- {
- double result2 = 0.0;
- foreach (var v in Arvosanat)
- {
- result2 += v.Arvosana;
- }
- double ka = result2 / Arvosanat.Count;
- return ka;
- }
- public double Keskihajonta()
- {
- double result = 0.0;
- foreach (var v in Arvosanat)
- {
- result += Math.Pow((v.Arvosana - Keskiarvo()), 2);
- }
- double hajonta = Math.Sqrt(result / Arvosanat.Count);
- return hajonta;
- }
- public double Average
- {
- get { return average; }
- set { value = Keskiarvo(); }
- }
- public double Deviation
- {
- get { return average; }
- set { value = Keskihajonta(); }
- }
- }
- internal interface IStatistics
- {
- double Average { get ; }
- double Deviation { get; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement