`publi c абстрактный класс TV реализует Logger {
protected int currentChannel;
protected int currentVolume;
protected String model;
public TV(String model)
{
this.model = model;
currentChannel = 2;
currentVolume = 10;
}
public void incChannel()
{
getcurrentChannel();
currentChannel = currentChannel + 1;
writeToLogFile("Increasing channel to " + currentChannel);
System.out.println("Increasing channel to " + currentChannel);
}
public void decChannel()
{
getcurrentChannel();
currentChannel = currentChannel - 1;
writeToLogFile("Decreasing channel to " + currentChannel);
System.out.println("Decreasing channel to " + currentChannel);
}
public void incVolume()
{
getcurrentVolume();
currentVolume = currentVolume + 1;
writeToLogFile("Increasing volume to " + currentVolume);
System.out.println("Increasing volume to " + currentVolume);
}
public void decVolume()
{
getcurrentVolume();
currentVolume = currentVolume - 1;
writeToLogFile("Decreasing volume to " + currentVolume);
System.out.println("Decreasing volume to " + currentVolume);
}
public void changeChannel(int currentChannel)
{
this.currentChannel = currentChannel;
writeToLogFile("Changing channel to " + currentChannel);
System.out.println("Changing channel to " + currentChannel);
}
public void writeToLogFile(String message)
{
model = getModel();
try {
FileReader fr = new FileReader(new File("./model.txt"));
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(new File("./model.txt"), true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
String line = br.readLine();
while (line != null) {
Scanner scanLine = new Scanner(line);
String mess = scanLine.next();
pw.println(message);
pw.println(mess);
line = br.readLine();
}
br.close();
pw.flush();
pw.close();
}
catch (FileNotFoundException e)
{
System.out.println("File not found.");
}
catch (IOException e)
{
System.out.println("An IO error occurred.");
}
}`
Когда я вызываю, запускаю мою программу, мой метод writeToLogFile не работает правильно. Когда он вызывается, он не создает текстовый файл по мере необходимости. Мне нужен метод writeToLogFile, чтобы создать файл и затем добавить его, когда он вызывается в других методах. Также у меня есть две модели телевизоров в этой программе. Когда я использую один из телевизоров (Sony), я хочу, чтобы он записывал в свой собственный файл журнала с именем Sony.txt. Затем у меня есть другой телевизор (LG), который также должен иметь свой собственный файл журнала. Нужно ли мне писать два отдельных оператора if, чтобы выяснить марку телевизора, а затем направить его в собственный файл журнала?