Программа не обновляет и не удаляет информацию, выдает следующую ошибку:
Я понимаю, что именно неправильно, но не понимаю, где именно в коде пропустила ошибку. Почему длина == 0?
Возможно, из-за того, что долго сижу, уже кипят мозги. Помогите понять, в чем проблема.
package com.javarush.task.task18.task1828;
public class Product {
private int id;
private String name;
private String price;
private String quantity;
private Product (int id, String name, String price, String quantity) {
this.id = id;
this.name = name;
this.price = price;
this.quantity = quantity;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public String toString() {
return String.format("\n%-8d%-30s%-8s%-4s", id, name, price, quantity);
}
public static Product getProduct(String string) {
String id = string.substring(0, 8).trim();
String name = string.substring(8, 38).trim();
String price = string.substring(38, 46).trim();
String quantity = string.substring(46, 50).trim();
return new Product(Integer.parseInt(id), name, price, quantity);
}
}