update lab4
This commit is contained in:
parent
f05125e298
commit
eb2ffae473
|
@ -3,7 +3,7 @@ package lab4;
|
|||
/**
|
||||
* My class Furniture.
|
||||
*/
|
||||
public class Furniture {
|
||||
public class Furniture<T> {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -13,6 +13,12 @@ public class Furniture {
|
|||
private int width;
|
||||
private int price;
|
||||
|
||||
private T additional;
|
||||
|
||||
public void setAdditional(T additional) {
|
||||
this.additional = additional;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param material
|
||||
|
@ -22,13 +28,18 @@ public class Furniture {
|
|||
* @param price
|
||||
*/
|
||||
public Furniture(String material, int length, int height, int width, int price) {
|
||||
this.material = material;
|
||||
// this.material = material;
|
||||
setMaterial(material);
|
||||
this.length = length;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public void setMaterial(String material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
public String getMaterial() {
|
||||
return material;
|
||||
}
|
||||
|
@ -52,4 +63,15 @@ public class Furniture {
|
|||
/*public Furniture() {
|
||||
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Furniture{" +
|
||||
"material='" + material + '\'' +
|
||||
", length=" + length +
|
||||
", height=" + height +
|
||||
", width=" + width +
|
||||
", price=" + price +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,19 +4,42 @@ import java.util.Arrays;
|
|||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// todo Comparable
|
||||
//todo equals+hashcode
|
||||
// todo JavaDoc
|
||||
final Furniture<Furniture> furniture1 = new Furniture<>("A", 1, 1, 1, 1);
|
||||
final Furniture<String> furniture2 = new Furniture<>("D", 1, 1, 1, 4);
|
||||
Furniture[] furnitureArray = {
|
||||
new Furniture("A", 1, 1, 1, 1),
|
||||
new Furniture("D", 1, 1, 1, 4),
|
||||
new Furniture("B", 1, 2, 1, 1),
|
||||
new Furniture("C", 1, 1, 3, 1),
|
||||
furniture1,
|
||||
furniture2,
|
||||
new Furniture("B", 1, 2, 1, 1),
|
||||
new Furniture("C", 1, 1, 3, 1),
|
||||
};
|
||||
|
||||
for (Furniture furniture : furnitureArray) {
|
||||
// System.out.println(furniture.getMaterial() + " " + furniture.getPrice());
|
||||
System.out.println(furniture);
|
||||
}
|
||||
System.out.println("+++++++++++++");
|
||||
|
||||
furniture1.setAdditional(new Furniture("Y", 1, 1, 1, 0));
|
||||
furniture2.setAdditional("new Furniture(\"Y\", 1, 1, 1, 0)");
|
||||
|
||||
// furnitureArray[0].setMaterial("E");
|
||||
|
||||
Arrays.sort(furnitureArray, (o1, o2) -> o1.getMaterial().compareTo(o2.getMaterial()));
|
||||
// todo print
|
||||
for (Furniture furniture : furnitureArray) {
|
||||
System.out.println(furniture);
|
||||
}
|
||||
|
||||
System.out.println("+++++++++++++");
|
||||
|
||||
// todo check
|
||||
Arrays.sort(furnitureArray, (o1, o2) -> Integer.compare(o2.getPrice(), o1.getPrice()));
|
||||
for (Furniture furniture : furnitureArray) {
|
||||
System.out.println(furniture);
|
||||
}
|
||||
|
||||
System.out.println("+++++++++++++");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue