```java public class Box { private int length; private int width; private int height; // 构造方法,初始化长、宽、高 public Box(int length, int width, int height) { this.length = length; this.width = width; this.height = height; } // 计算体积的方法 public int volume() { return length * width * height; } // 计算表面积的方法 public int surfaceArea() { return 2 * (length * width + length * height + width * height); } // 将长、宽、高、体积和表面积转换为字符串的方法 public String toString() { return "长:" + length + ",宽:" + width + ",高:" + height + ",体积:" + volume() + ",表面积:" + surfaceArea(); } public static void main(String[] args) { Box box = new Box(5, 3, 2); System.out.println(box.toString()); } } ``` 额外需要注意的逻辑点: 1. 确保传入的长、宽、高值是有效的整数,避免出现负数或非整数的情况。 2. 在计算体积和表面积时,要注意数据类型的转换和计算的准确性。 3. 在主函数中创建对象并调用方法时,要根据实际需求传递合适的参数值。 [2024-11-20 19:03:47 | AI写代码神器 | 335点数解答]