/
pandapo777
/
JavaStepik
Обзор
Документация
Войти
/
pandapo777
/
JavaStepik
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
OOP/src/box/Box.java
79 строк
2 KB
pandapo777
ДЗ интерфейсы
06 апр 2025, 00:20
06 апр 2025, 00:20
56ecf60
Код
Авторство
О чём код?
package box; public class Box { protected static double length; protected static double width; protected static double height; public Box() { this(10); } public Box(Box another) { this(another.length, another.width, another.height); } public Box copy() { return new Box(this.length, this.width, this.height); } public Box increase(){ return new Box(this.length * 2, this.width * 2, this.height * 2); } public Box(double size) { // this.length = size; // this.width = size; // this.height = size; this(size, size, size); } public Box(double width, double length, double height) { this.width = width; this.length = length; this.height = height; } public void setDimens (double length, double width, double height){ this.length = length; this.height = height; this.width = width; } // void compare (Box.Box another) { // double currentVolume = getVolume(); // double anotherVolume = another.getVolume(); // if(currentVolume > anotherVolume) { // System.out.println("currentVolume > anotherVolume"); // } else if (currentVolume < anotherVolume) { // System.out.println("currentVolume < anotherVolume"); // } else { // System.out.println("currentVolume = anotherVolume"); // } // } public int compare (Box another) { double currentVolume = getVolume(); double anotherVolume = another.getVolume(); int result; if(currentVolume > anotherVolume) { result = 1; } else if (currentVolume < anotherVolume) { result = -1; } else { result = 0; } return result; } public double getVolume() { return length * width * height; } public void showVolume() { double volume = length * width * height; System.out.println(volume); } public void showInfo() { System.out.println("Длина: " + length + "\nШирина: " + width + "\nВысота: " + height); } }