У меня есть текстовый файл (Items.txt), в котором содержатся следующие данные: дата, имя, описание и цена, и он отформатирован следующим образом:
31/10/2018, Food, Hamburger, 10.00
31/10/2018, Clothes, Hoodie, 50.00
1/11/2018, Games, Controller, 150.00
1/11/2018, Food, Chips, 5.00
Как получить общую суммутолько еда?Вот фрагмент, с которым я работал до сих пор:
public static double totalFoodExpense(byte choiceCode, byte[] expenseChoiceCode, double[]totalExpense) throws IOException{
double total =0;
double amount = 0;
String expense= "";
xpenseCode = 0;
Scanner kb = new Scanner(System.in);
Scanner read = new Scanner(new File("Items.txt"));
System.out.println("Enter the expense code to determine the total amount that you have spent on");
System.out.println("Codes < Food(1), Clothes(2), Games(3), > \n Please " +
"just enter a number");
xpenseCode = Byte.parseByte(kb.nextLine());
while (read.hasNextLine()){
String oneLine = read.nextLine();
String[] parts = oneLine.split(",");
if(xpenseCode == 1){
//Nothing yet
}
}
return total;
}
Пользователь вводит число (1 для еды, 2 для одежды и 3 для игр), чтобы определить общее количество этого определенного предмета.Таким образом, ожидаемый результат будет выглядеть так:
Enter the expense code to determine the total amount that you have spent on
Codes < Food(1), Clothes(2), Games(3), > Please just enter a number:
1 <--user input
The total expense of Food is 15.00