package src.Service;
import src.FinancialRecord.Expense;
import src.FinancialRecord.Income;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
public class Service implements OutputRecorder {
private Expense[] getExpense;
private Income[] getIncome;
public Service(){
}
@Override
public void add_newExpense(Income var1) throws IOException {
}
public void add_newExpense(Expense newRecorder) throws IOException {
String category1 = newRecorder.getCategory();
String details1 = newRecorder.getDetails();
String date1 = newRecorder.getDate();
double amount1=newRecorder.getAmount();
ArrayList<String> arrayList = new ArrayList();
arrayList.add(category1);
arrayList.add(details1);
arrayList.add(date1);
arrayList.add(String.valueOf(amount1));
BufferedWriter writer = new BufferedWriter(new FileWriter("E:\\学习\\记账本.txt", true));
try {
Iterator var7 = arrayList.iterator();
while(var7.hasNext()) {
String str1 = (String)var7.next();
writer.write(Arrays.toString(str1.split("\\|")));
writer.flush();
}
writer.newLine();
} catch (IOException var17) {
} finally {
try {
writer.close();
} catch (IOException var16) {
throw new RuntimeException(var16);
}
}
}
@Override
public void add_newIncome() throws IOException {
add_newIncome(null);
}
public void add_newIncome(Income newRecorder) throws IOException {
String category1 = newRecorder.getCategory();
String details1 = newRecorder.getDetails();
String date1 = newRecorder.getDate();
double amount1=newRecorder.getAmount();
ArrayList<String> arrayList = new ArrayList();
arrayList.add(category1);
arrayList.add(details1);
arrayList.add(date1);
arrayList.add(String.valueOf(amount1));
BufferedWriter writer = new BufferedWriter(new FileWriter("E:\\学习\\记账本.txt", true));
try {
Iterator var7 = arrayList.iterator();
while(var7.hasNext()) {
String str1 = (String)var7.next();
writer.write(Arrays.toString(str1.split("\\|")));
writer.flush();
}
writer.newLine();
} catch (IOException var17) {
} finally {
try {
writer.close();
} catch (IOException var16) {
throw new RuntimeException(var16);
}
}
}
@Override
public void showRecoeder() throws IOException {
}
public void showRecorder() throws IOException {
ArrayList<String> arrayList2 = new ArrayList();
BufferedReader bufferedReader = new BufferedReader(new FileReader("E:\\学习\\记账本.txt"));
String s;
while((s = bufferedReader.readLine()) != null) {
arrayList2.add(s);
arrayList2.add("\t\t\t\n");
}
System.out.print(" ");
System.out.println(arrayList2);
bufferedReader.close();
}
}