diff --git a/Emne 3/Innkapsling/Innkapsling/Program.cs b/Emne 3/Innkapsling/Innkapsling/Program.cs index 495de0d..b42b144 100644 --- a/Emne 3/Innkapsling/Innkapsling/Program.cs +++ b/Emne 3/Innkapsling/Innkapsling/Program.cs @@ -10,6 +10,11 @@ while (true) var number = Convert.ToInt32(numberStr); stats.AddNumber(number); - stats.Show(); + Console.Clear(); + Console.WriteLine( + $"Antall tall: {stats.NumberCount} " + + $"Sum: {stats.Sum} " + + $"Snitt: {stats.Mean}" + ); } \ No newline at end of file diff --git a/Emne 3/Innkapsling/Innkapsling/Stats.cs b/Emne 3/Innkapsling/Innkapsling/Stats.cs index c0a8aff..d564f63 100644 --- a/Emne 3/Innkapsling/Innkapsling/Stats.cs +++ b/Emne 3/Innkapsling/Innkapsling/Stats.cs @@ -1,29 +1,16 @@ namespace Innkapsling; -public class Stats +internal class Stats { - private int[] _numbers; - private int _numberCount; - - public Stats() - { - _numbers = new int[10]; - } + public int NumberCount { get; private set; } + public int Sum { get; private set; } + public float Mean => (float)Sum / NumberCount; + public void AddNumber(int number) { - _numbers[_numberCount] = number; - _numberCount++; + Sum += number; + NumberCount++; } - public void Show() - { - var sum = _numbers.Sum(); - Console.Clear(); - Console.WriteLine( - $"Antall tall: {_numberCount} " + - $"Sum: {sum} " + - $"Snitt: {(float)sum / _numberCount}" - ); - } } \ No newline at end of file