/
NikolayIvkin
/
JavaExercises1
Обзор
Документация
Войти
/
NikolayIvkin
/
JavaExercises1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Clases/BoxDemo.java
64 строки
1 KB
germa
Объекты как параметры метода/сравнение объектов
30 ноя 2024, 21:05
30 ноя 2024, 21:05
8fe7634
Код
Авторство
О чём код?
package Clases; public class BoxDemo { public static void main(String[] args) { Box MyBox = new Box(); MyBox.setDim(12,3,5); MyBox.getVolume(); Box myBox1 = new Box(); myBox1.setDim(3,5,53); myBox1.getVolume(); } } class Box{ private double width; private double height; private double depth; Box(){ width = -1; height = -1; depth = -1; } Box(Box ob){ width = ob.width; height = ob.height; depth = ob.depth; } Box(double width, double height, double depth){ this.width = width; this.height = height; this.depth = depth; } Box(double length){ this.width = this.height = this.depth = length; } void setDim(int width, int height, int depth) { this.width = width; this.height = height; this.depth = depth; } public void getVolume() { System.out.println("Объём коробки равен " + (width * height * depth)); } @Override public String toString() { return "Box width=" + width + ", height=" + height + ", depth=" + depth; } }