mirror of
https://github.com/ASDjonok/OOP_IO-2x_2023.git
synced 2026-04-19 20:41:50 +03:00
update lab4 (+ added JavaDoc)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user