Не проходят пункты 4, 5, 6. Переписывала код по-разному, все равно не проходит. В чем я ошиблась?
package com.javarush.task.task18.task1827;
/*
Прайсы
*/
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName = reader.readLine();
reader.close();
ArrayList<String>list = new ArrayList<>();
if (args.length == 0){
return;
}
if (args.length == 4 && args[0].equals("-c")){
File file = new File(fileName);
BufferedReader buff = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line;
while ((line = buff.readLine()) != null){
list.add(line);
}
for (String a : list){
System.out.println(a);
}
System.out.println();
buff.close();
ArrayList<Integer>list1 = new ArrayList<>();
for (int i = 1; i < list.size(); i++){
list1.add(Integer.valueOf((list.get(i).substring(0, 8).trim())));
}
int maxID = list1.get(0);
for (int i = 1; i < list1.size(); i++){
if (list1.get(i) > maxID){
maxID = list1.get(i);
}
}
String id = String.valueOf(maxID);
// System.out.println(id);
if (id.length() > 8){
id = id.substring(0, 8);
}
else {
int x = 8 - id.length();
for (int i = 0; i < x; i++){
id = id + " ";
}
}
id = String.format("%-8d", ++maxID);
if (args[1].length() > 30){
args[1] = args[1].substring(0, 30);
}
else {
int x = 30 - args[1].length();
for (int i = 0; i < x; i++){
args[1] = args[1] + " ";
}
}
String productName = args[1];
if (args[2].length() > 8){
args[2] = args[2].substring(0, 8);
}
else {
int x = 8 - args[2].length();
for (int i = 0; i < x; i++){
args[2] = args[2] + " ";
}
}
String price = args[2];
if (args[3].length() > 4){
args[3] = args[3].substring(0, 4);
}
else {
int x = 4 - args[3].length();
for (int i = 0; i < x; i++){
args[3] = args[3] + " ";
}
}
String quantity = args[3];
String allLine = id + productName + price + quantity;
list.add(list.size(), allLine);
for (String a : list){
System.out.println(a);
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
final String LINE_SEPARATOR = System.getProperty("line.separator");
for (int i = 0; i < list.size(); i++){
fileOutputStream.write(list.get(i).getBytes());
fileOutputStream.write(LINE_SEPARATOR.getBytes());
}
fileOutputStream.close();
}
}
}