|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.Globalization; |
3 | 4 | using System.IO;
|
4 | 5 | using System.Linq;
|
5 | 6 | using System.Text;
|
6 | 7 | using System.Threading.Tasks;
|
7 | 8 |
|
8 | 9 | namespace Liquid
|
9 | 10 | {
|
| 11 | + // Read from a csv file |
| 12 | + // Get the total value of insured houses |
| 13 | + // Store the Value by country |
| 14 | + // The last line must have the total and the current date |
| 15 | + // ----- |
| 16 | + // Client 1: Ignore Residential type of housing. |
| 17 | + // Client 2: Ignore Commercial type of housing. |
10 | 18 | class Program
|
11 | 19 | {
|
12 | 20 | static void Main(string[] args)
|
13 | 21 | {
|
| 22 | + var client = 2; |
14 | 23 | var fileLines = File.ReadAllLines(".\\FL_insurance_sample.csv");
|
15 |
| - |
| 24 | + var output = new StreamWriter(File.OpenWrite("MyOutput.csv")); |
| 25 | + output.WriteLine($"Country,Value"); |
| 26 | + var total = 0.0; |
16 | 27 | for (var i = 1; i < fileLines.Length; i++)
|
17 | 28 | {
|
18 |
| - |
| 29 | + if (double.TryParse(fileLines[i].Split(',')[8], NumberStyles.Any, CultureInfo.InvariantCulture, out var value)) |
| 30 | + { |
| 31 | + if (client == 1) |
| 32 | + { |
| 33 | + if (fileLines[i].Split(',')[15] == "Residential") |
| 34 | + { |
| 35 | + output.WriteLine($"{fileLines[i].Split(',')[3]},{value.ToString("F2", CultureInfo.InvariantCulture)}"); |
| 36 | + total += value; |
| 37 | + } |
| 38 | + } |
| 39 | + if (client == 2) |
| 40 | + { |
| 41 | + if (fileLines[i].Split(',')[15] == "Commercial") |
| 42 | + { |
| 43 | + output.WriteLine($"{fileLines[i].Split(',')[3]},{value.ToString("F2", CultureInfo.InvariantCulture)}"); |
| 44 | + total += value; |
| 45 | + } |
| 46 | + } |
| 47 | + } |
19 | 48 | }
|
20 | 49 |
|
21 |
| - |
22 |
| - |
| 50 | + output.WriteLine("{0},{1}", total.ToString("F2", CultureInfo.InvariantCulture), DateTime.Now.ToString("d", CultureInfo.InvariantCulture)); |
| 51 | + output.Flush(); |
| 52 | + output.Close(); |
23 | 53 | }
|
24 | 54 | }
|
25 | 55 | }
|
0 commit comments