-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathCalculator.cs
More file actions
34 lines (29 loc) · 816 Bytes
/
Calculator.cs
File metadata and controls
34 lines (29 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
using System.Text;
namespace StringCalculator.Logic
{
public class Calculator
{
public int Sum(int[] numbers)
{
List<int> negatives = new List<int>();
int sum = 0;
foreach (int number in numbers)
if (number < 0)
negatives.Add(number);
else
if (number <= 1000)
sum += number;
if (negatives.Count >0)
throw new NegativesNotAllowedException(negatives.ToArray(),"numbers");
else
return sum;
}
public int Sum(string input)
{
InputParser ip = new InputParser();
return Sum(ip.Parse(input));
}
}
}