Search for products in a file

3. Katas

Problem:

Given a file (txt format) in which is information about the products: the name, the country into which the goods are exported and the volume in which it is imported.

Example File:
Name1 Country1 Volume1
Name2 Country2 Volume2
.... .... ....

Task:

Write a program that looks for a product from a file by name and returns such a line:

"Product: N; Counties to export: C1, C2,..; Volume: P;", where N is the name of the product, [C1, C2, ..] -the countries to which the goods are exported, P is the total volume from all countries.

!Tip, try this with the help of functions (this will teach you to break the program into small parts and use them several times without copying the code, in contrast to the linear programs)

Data to verify:

Go to the data folder where you will find txt files for verification, the results should be as follows:

where (Name) means the name of the product to be searched for.
  1. data1.txt (Name1) --> "Product: Name1; Countries for export: Country1; Scope: 14;"
  2. data1.txt (Name1) --> "Product: Name1; Countries for export: Country1 Country2 Country3; Amount: 148;"
  3. data1.txt (Name2) --> "Product: Name2; Countries for export: Country2 Country3 Country4; Amount: 331;"
where "-->" means after starting the program

What's next ?

The program does not come out or works not exactly,go to the solution folder and look at the explanation for solving the problem, this will help you.

If you have everything turned out, you can go to the solution package and compare your solution with the one that's there.

If your decision does not coincide with my decision, then I'm very happy for you. Please share it with me, I will be very grateful to you and then I will add it to the solution folder. How to add your solution, see here

See Solution or visit Github page: