Task :
There is a file. The number of lines is unknown. Each line of the file is a record of the form:
Покупатель Товар Количество It is necessary to create an array with all customers.
For each customer, calculate the number of items he purchased for each type of product.
List in alphabetical order the names of buyers.
Input from file:
Иванов газета 10 Петров ручка 5 Николаев тетрадь 3 Иванов ручка 2 Николаев ручка 1 Петров тетрадь 2 Николаев газета 1 Displayed data:
Иванов : газета - 10 шт ; ручка - 5 шт ; Николаев : газета - 1 шт ; ручка - 1 шт ; тетрадь - 3 шт; Петров : ручка - 5 шт ; тетрадь - 2 шт; My code is:
package semnadcat; import java.io.IOException; import java.io.*; /** * * @author Марат */ public class Semnadcat2 { public static void main(String args[]) { try(FileReader reader = new FileReader("C:\\SomeDir\\notes3.txt")){ int c; while((c=reader.read())!=-1){ System.out.print((char)c); } } catch(IOException ex){ System.out.println(ex.getMessage()); } System.out.println(" "); } } My mistakes:
I do not understand how you can save the file data to an array. It can only be character-by-word pull information on the screen.