Finished the lesson
This commit is contained in:
parent
e1720b362f
commit
32933758fe
|
@ -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}"
|
||||
);
|
||||
|
||||
}
|
|
@ -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}"
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue