From 277f8f82f61b99221bf71b32bc3c3adbfc82614b Mon Sep 17 00:00:00 2001 From: Oleksii Aleshchenko Date: Thu, 25 May 2023 15:06:01 +0300 Subject: [PATCH] update lab4 --- src/lab4/Furniture.java | 24 ++++++++++++++++-------- src/lab4/Main.java | 13 +++++++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/lab4/Furniture.java b/src/lab4/Furniture.java index f7ecea1..d8dce60 100644 --- a/src/lab4/Furniture.java +++ b/src/lab4/Furniture.java @@ -1,9 +1,11 @@ package lab4; -/** - * My class Furniture. - */ -public class Furniture { + +///** +// * My class Furniture. +// */ +//todo uncomment /**/ +public /*abstract*/ class Furniture/**/ implements Comparable/**/{ /** * */ @@ -13,11 +15,11 @@ public class Furniture { private int width; private int price; - private T additional; +// private T additional; - public void setAdditional(T additional) { - this.additional = additional; - } +// public void setAdditional(T additional) { +// this.additional = additional; +// } /** * @@ -74,4 +76,10 @@ public class Furniture { ", price=" + price + '}'; } + + @Override + public int compareTo(Object o) { + return /*this.*/price - ((Furniture) o).price; +// return /*this.*/material.compareTo(((Furniture) o).material); + } } diff --git a/src/lab4/Main.java b/src/lab4/Main.java index 67b3fb7..76c1ce9 100644 --- a/src/lab4/Main.java +++ b/src/lab4/Main.java @@ -4,11 +4,16 @@ import java.util.Arrays; public class Main { public static void main(String[] args) { + System.out.println(Integer.MIN_VALUE - 1); // todo Comparable //todo equals+hashcode // todo JavaDoc - final Furniture furniture1 = new Furniture<>("A", 1, 1, 1, 1); - final Furniture furniture2 = new Furniture<>("D", 1, 1, 1, 4); + final Furniture/**/ furniture1 = new Furniture("A", 1, 1, 1, 1); + final Furniture/**/ furniture2 = new Furniture("F", 1, 1, 1, 4); + + System.out.println(furniture1.compareTo(furniture2)); + System.out.println(furniture1.compareTo("furniture2")); + Furniture[] furnitureArray = { furniture1, furniture2, @@ -22,8 +27,8 @@ public class Main { } System.out.println("+++++++++++++"); - furniture1.setAdditional(new Furniture("Y", 1, 1, 1, 0)); - furniture2.setAdditional("new Furniture(\"Y\", 1, 1, 1, 0)"); +// furniture1.setAdditional(new Furniture("Y", 1, 1, 1, 0)); +// furniture2.setAdditional("new Furniture(\"Y\", 1, 1, 1, 0)"); // furnitureArray[0].setMaterial("E");