Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Arvioinnit
  9. {
  10.     public class Arviointi
  11.     {
  12.         private string opiskelijaNro;
  13.         private readonly double[] koetulokset;
  14.         private string arviontipvm = DateTime.Now.ToShortDateString();
  15.         private short arvosana;
  16.  
  17.         public double I { get; set; }
  18.         public double II { get; set; }
  19.         public double III { get; set; }
  20.         public double Koe { get; set; }
  21.         public short Arvosana
  22.         {
  23.             get { return arvosana; }
  24.             set
  25.             {
  26.                 if ((value >= 0) && (value <= 5))
  27.                 {
  28.                     arvosana = value;
  29.                 }
  30.                 if ((value > 5) || (value < 0))
  31.                 {
  32.                     throw new ArgumentOutOfRangeException("Arvosana vain välillä [0,5]");
  33.                 }
  34.             }
  35.         }
  36.         public string Arviointipvm
  37.         {
  38.             get { return arviontipvm; }
  39.             set { arviontipvm = value; }
  40.  
  41.         }
  42.         public string OpiskelijaNro
  43.         {
  44.             get { return opiskelijaNro; }
  45.             set
  46.             {
  47.                 if (opiskelijaNro.Length == 7)
  48.                 {
  49.                     if (Convert.ToInt32(opiskelijaNro.Substring(0, 2)) <= DateTime.Now.Year - 2000)
  50.                     {
  51.                         if (Koulutusalakoodit.IsKoulutusala(opiskelijaNro.Substring(2,2)))
  52.                         {
  53.                             if (Convert.ToInt32(opiskelijaNro.Substring(4, 3)) > 0)
  54.                             {
  55.                                 opiskelijaNro = value;
  56.                             }
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.         enum KOULUTUSALAT { TEKNIIKKA = 1, TALOUS, TERVEYS, TAIDE }
  63.         public struct Koulutusalakoodit
  64.         {
  65.             KOULUTUSALAT ala;
  66.             readonly string koodi;
  67.             Koulutusalakoodit(KOULUTUSALAT kOULUTUSALAT)
  68.             {
  69.                 ala = kOULUTUSALAT;
  70.                 koodi = string.Format("{0}{1}", 0, ala);
  71.             }
  72.  
  73.             public static bool IsKoulutusala(string foo)
  74.             {
  75.                 if ((foo.Length == 2) && (Enum.IsDefined(typeof(KOULUTUSALAT), Convert.ToInt16(foo))))
  76.                 {
  77.                     return true;
  78.                 }
  79.                 else
  80.                 {
  81.                     return false;
  82.                 }
  83.             }
  84.         }
  85.     }
  86.     public class OpintojaksoArvioinnit : IStatistics
  87.     {
  88.         private double average;
  89.         private double deviation;
  90.         ObservableCollection<Arviointi> arvosanat = new ObservableCollection<Arviointi>();
  91.         public short[] Numerot = new short[] { 0, 1, 2, 3, 4, 5 };
  92.         public ObservableCollection<Arviointi> Arvosanat
  93.         {
  94.             get { return arvosanat; }
  95.             set
  96.             {
  97.                 if (arvosanat != null)
  98.                 {
  99.                     arvosanat = value;
  100.                 }
  101.                 else
  102.                 {
  103.                     throw new ArgumentNullException("Observations can not be null");
  104.                 }
  105.             }
  106.         }
  107.         public double Keskiarvo()
  108.         {
  109.             double result2 = 0.0;
  110.             foreach (var v in Arvosanat)
  111.             {
  112.                 result2 += v.Arvosana;
  113.             }
  114.             double ka = result2 / Arvosanat.Count;
  115.             return ka;
  116.         }
  117.         public double Keskihajonta()
  118.         {
  119.             double result = 0.0;
  120.             foreach (var v in Arvosanat)
  121.             {
  122.                 result += Math.Pow((v.Arvosana - Keskiarvo()), 2);
  123.             }
  124.             double hajonta = Math.Sqrt(result / Arvosanat.Count);
  125.             return hajonta;
  126.         }
  127.  
  128.         public double Average
  129.         {
  130.             get { return average; }
  131.             set { value = Keskiarvo(); }
  132.         }
  133.         public double Deviation
  134.         {
  135.             get { return average; }
  136.             set { value = Keskihajonta(); }
  137.         }
  138.     }
  139.  
  140.     internal interface IStatistics
  141.     {
  142.         double Average { get ; }
  143.         double Deviation { get; }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement