update lab4 (+ added JavaDoc)

This commit is contained in:
Oleksii Aleshchenko
2023-06-01 15:16:50 +03:00
parent 1583e33ab3
commit 9c691d2c72
107 changed files with 11209 additions and 9 deletions

View File

@@ -1,13 +1,16 @@
package lab4;
///**
// * My class Furniture.
// */
import java.util.Objects;
/**
* My class Furniture.
*/
//todo uncomment /*<Furniture>*/
public /*abstract*/ class Furniture/*<T>*/ implements Comparable<Furniture> {
/**
*
* Material with which furniture was made of
*/
private String material;
private int length;
@@ -22,7 +25,9 @@ public /*abstract*/ class Furniture/*<T>*/ implements Comparable<Furniture> {
// }
/**
* @param material
* Our class constructor.
*
* @param material Material with which furniture was made of
* @param length
* @param height
* @param width
@@ -90,4 +95,22 @@ public /*abstract*/ class Furniture/*<T>*/ implements Comparable<Furniture> {
// : -material.compareTo(o.material);
: o.material.compareTo(material);
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Furniture furniture = (Furniture) o;
return length == furniture.length && height == furniture.height && width == furniture.width
&& price == furniture.price && material.equals(furniture.material);
}
@Override
public int hashCode() {
return Objects.hash(material, length, height, width, price);
}
}

View File

@@ -6,10 +6,14 @@ import java.util.Comparator;
public class Main {
public static void main(String[] args) {
System.out.println(Integer.MIN_VALUE - 1);
//todo equals+hashcode
// todo JavaDoc
final Furniture/*<Furniture>*/ furniture1 = new Furniture("A", 1, 1, 1, 1);
final Furniture/*<String>*/ furniture2 = new Furniture("F", 1, 1, 1, 4);
/*final*/ Furniture/*<Furniture>*/ furniture1 = new Furniture("A", 1, 1, 1, 1);
final Furniture/*<String>*/ furniture2 = new Furniture("A", 2, 1, 1, 1);
// furniture1 = null;
System.out.println(furniture1.equals(furniture2));
System.out.println(furniture1.hashCode());
System.out.println(furniture2.hashCode());
System.out.println(furniture1.compareTo(furniture2));
// System.out.println(furniture1.compareTo("furniture2"));