Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/BackPocket.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/BottomHem.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/Button.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/FrontPocket.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/InsidePart.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/Jeans.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/JeansParts.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/Main.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/OutsidePart.class
Binary file not shown.
Binary file modified out/production/JavaLab1_Clothes/com/Jeans/Zipper.class
Binary file not shown.
4 changes: 2 additions & 2 deletions src/com/Jeans/BackPocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public class BackPocket extends JeansParts{
private Button backPocketButton;

public BackPocket(String material, double materialSize, String color, Button backPocketButton) {
super(material, materialSize, color);
public BackPocket(String material, double materialSize, String color, Button backPocketButton, int price) {
super(material, materialSize, color, price);
this.backPocketButton = backPocketButton;
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/Jeans/BottomHem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class BottomHem extends JeansParts{

public BottomHem(String material, double materialSize, String color) {
super(material, materialSize, color);
public BottomHem(String material, double materialSize, String color, int price) {
super(material, materialSize, color, price);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/com/Jeans/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public class Button extends JeansParts{
private String buttonType;

public Button(String material, double materialSize, String color, String buttonType) {
super(material, materialSize, color);
public Button(String material, double materialSize, String color, String buttonType, int price) {
super(material, materialSize, color, price);
this.buttonType = buttonType;
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/Jeans/FrontPocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class FrontPocket extends JeansParts {

public FrontPocket(String material, double materialSize, String color) {
super(material, materialSize, color);
public FrontPocket(String material, double materialSize, String color, int price) {
super(material, materialSize, color, price);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/com/Jeans/InsidePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class InsidePart extends JeansParts{

public InsidePart(String material, double materialSize, String color) {
super(material, materialSize, color);
public InsidePart(String material, double materialSize, String color, int price) {
super(material, materialSize, color, price);
}

@Override
Expand Down
16 changes: 15 additions & 1 deletion src/com/Jeans/Jeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ public class Jeans {
private double width;
private double length;
private final JeansType type;
private int price;

public Jeans(Collection<JeansParts> parts, String name, double width, double length, JeansType type) throws JeansException {
if(name.equals("")) {
if (name.equals("")) {
throw new JeansException();
}
this.parts = parts;
Expand All @@ -23,6 +24,18 @@ public Jeans(Collection<JeansParts> parts, String name, double width, double len

}

public Collection<JeansParts> getParts() {
return parts;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getName() {
return name;
}
Expand All @@ -49,6 +62,7 @@ public JeansType getType() {

public Jeans addPart(JeansParts part) {
this.parts.add(part);
this.price += part.price;
return this;
}

Expand Down
20 changes: 18 additions & 2 deletions src/com/Jeans/JeansParts.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ public abstract class JeansParts implements JeansComponent {
protected String material;
protected double materialSize;
protected String color;
protected int price;

public JeansParts(String material, double materialSize, String color) {
public JeansParts(String material, double materialSize, String color, int price) {
this.material = material;
this.materialSize = materialSize;
this.color = color;
this.price = price;
}

public int getPrice() {
return price;
}

public void setPrice(int price) {
this.price = price;
}

public String getMaterial() {
Expand All @@ -35,5 +45,11 @@ public void setColor(String color) {
this.color = color;
}

public void print(){}
@Override
public String toString() {
return this.material;
}

public void print() {
}
}
79 changes: 63 additions & 16 deletions src/com/Jeans/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.Jeans;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.OptionalInt;
import java.util.stream.Collectors;

public class Main {

Expand All @@ -14,41 +18,84 @@ public static void main(String[] args) {
Jeans myJeans2 = new Jeans(new ArrayList<>(), "Name", 28, 30, JeansType.flare);

myJeans.addPart(new BackPocket("Denim", 0.5, "blue",
new Button("steel", 0.02, "black", "Pocket Button")))
.addPart(new BottomHem("Denim", 0.1, "blue"))
.addPart(new Button("steel", 0.05, "black", "Common Button"))
.addPart(new FrontPocket("Denim", 0.3, "blue"))
.addPart(new InsidePart("Cotton", 5, "black"))
new Button("steel", 0.02, "black", "Pocket Button", 150), 150))
.addPart(new BottomHem("Denim", 0.1, "blue", 150))
.addPart(new Button("steel", 0.05, "black", "Common Button", 250))
.addPart(new FrontPocket("Denim", 0.3, "blue", 150))
.addPart(new InsidePart("Cotton", 5, "black", 150))
.addPart(new OutsidePart("Denim", 5, "blue",
new OutsidePart.Pattern("Round", "Medium", "white")))
.addPart(new Zipper("Steel", 0.1, "black", 0.15));
new OutsidePart.Pattern("Round", "Medium", "white"), 150))
.addPart(new Zipper("steel", 0.1, "black", 0.15, 150));

printJeans(myJeans);

myJeans2.addPart(new BackPocket("Denim", 0.6, "blue",
new Button("steel", 0.02, "black", "Pocket Button")))
.addPart(new BottomHem("Denim", 0.1, "blue"))
.addPart(new Button("steel", 0.04, "black", "Common Button"))
.addPart(new FrontPocket("Denim", 0.2, "blue"))
.addPart(new InsidePart("Cotton", 6, "black"))
new Button("steel", 0.02, "black", "Pocket Button", 200), 200))
.addPart(new BottomHem("Denim", 0.1, "blue", 200))
.addPart(new Button("steel", 0.04, "black", "Common Button", 200))
.addPart(new FrontPocket("Denim", 0.2, "blue", 200))
.addPart(new InsidePart("Cotton", 6, "black", 200))
.addPart(new OutsidePart("Denim", 6, "blue",
new OutsidePart.Pattern("Round", "Medium", "white")))
.addPart(new Zipper("Steel", 0.1, "black", 0.2));
new OutsidePart.Pattern("Round", "Medium", "white"), 200))
.addPart(new Zipper("steel", 0.1, "black", 0.2, 200));

System.out.println(myJeans.equals(myJeans2));
System.out.println();


int price = myJeans.getParts().stream().filter(part -> part.getMaterial().equals("steel"))
.mapToInt(part -> part.getPrice()).reduce(0, (left, right) -> left + right);

System.out.println("Price: " + price);


OptionalInt maxPrice = myJeans.getParts().stream().mapToInt(part -> {
if (part.getMaterial().equals("steel")) {
return part.getPrice();
}
return 0;
}).max();

System.out.println("Max Price: " + maxPrice.getAsInt());


int averagePrice = myJeans.getParts().stream().filter(part -> part.getMaterial().equals("steel"))
.mapToInt(part -> part.getPrice()).reduce(0, (left, right) -> left + right)
/ myJeans.getParts().stream().filter(part -> part.getMaterial() == "steel").toArray().length;

System.out.println("Average Price: " + averagePrice);


var arr = myJeans.getParts().
stream().collect(Collectors.groupingBy(part -> part.getMaterial().equals("steel") ? "suitable" : "unsuitable"));

System.out.println("Suitable: " + arr.get("suitable"));
System.out.println("Unsuitable: " + arr.get("unsuitable"));


ArrayList<Jeans> jeansList = new ArrayList<>();
jeansList.add(myJeans);
jeansList.add(myJeans2);

int totalPrice = jeansList.stream().flatMap(jeans -> jeans.getParts().stream())
.mapToInt(part -> part.getPrice()).reduce(0, Integer::sum);

System.out.println("Total price: " + totalPrice);
System.out.println();


} catch (JeansException e) {
System.err.println(e.getMessage());
}


Button button = new Button("steel", 0.04, "black", "Common Button");
Button button2 = new Button("plastic", 0.05, "grey", "Common Button");
Button button = new Button("steel", 0.04, "black", "Common Button", 200);
Button button2 = new Button("plastic", 0.05, "grey", "Common Button", 200);

System.out.println(button.equals(button2));
System.out.println();


int number1 = 10;
int number2 = 20;
String word = "Hello number ";
Expand Down
4 changes: 2 additions & 2 deletions src/com/Jeans/OutsidePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public class OutsidePart extends JeansParts {
private Pattern pattern;

public OutsidePart(String material, double materialSize, String color, Pattern pattern) {
super(material, materialSize, color);
public OutsidePart(String material, double materialSize, String color, Pattern pattern, int price) {
super(material, materialSize, color, price);
this.pattern = pattern;
}

Expand Down
4 changes: 2 additions & 2 deletions src/com/Jeans/Zipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
public class Zipper extends JeansParts {
private double zipperLength;

public Zipper(String material, double materialSize, String color, double zipperLength) {
super(material, materialSize, color);
public Zipper(String material, double materialSize, String color, double zipperLength, int price) {
super(material, materialSize, color, price);
this.zipperLength = zipperLength;
}

Expand Down
4 changes: 2 additions & 2 deletions test/com/Jeans/BackPocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BackPocketTest {
public void checkBackPocketConstructor() {

BackPocket backPocket = new BackPocket("Denim", 0.5, "blue",
new Button("steel", 0.02, "black", "Pocket Button"));
new Button("steel", 0.02, "black", "Pocket Button", 200), 200);

Assertions.assertEquals("Denim", backPocket.getMaterial());
Assertions.assertEquals(0.5, backPocket.getMaterialSize());
Expand All @@ -28,7 +28,7 @@ void testBackPocket() {
Button button = Mockito.mock(Button.class);
button.setButtonType("Pocket Button");
Mockito.when(button.getButtonType()).thenReturn(str);
BackPocket backPocket = new BackPocket("Denim", 0.5, "blue", button);
BackPocket backPocket = new BackPocket("Denim", 0.5, "blue", button, 200);
Assertions.assertEquals(backPocket.getBackPocketButton().getButtonType(), str);
Mockito.verify(button).getButtonType();
}
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/BottomHemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class BottomHemTest {
@Test
public void checkBottomHemConstructor() {

BottomHem bottomHem = new BottomHem("Denim", 0.1, "blue");
BottomHem bottomHem = new BottomHem("Denim", 0.1, "blue", 200);

Assertions.assertEquals("Denim", bottomHem.getMaterial());
Assertions.assertEquals(0.1, bottomHem.getMaterialSize());
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/ButtonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ButtonTest {
@Test
public void checkButtonConstructor() {

Button button = new Button("steel", 0.04, "black", "Common Button");
Button button = new Button("steel", 0.04, "black", "Common Button", 200);

Assertions.assertEquals(0.04, button.getMaterialSize());
Assertions.assertEquals("Common Button", button.getButtonType());
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/FrontPocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class FrontPocketTest {
@Test
public void checkFrontPocketConstructor() {

FrontPocket frontPocket = new FrontPocket("Denim", 0.3, "blue");
FrontPocket frontPocket = new FrontPocket("Denim", 0.3, "blue", 200);

Assertions.assertEquals("Denim", frontPocket.getMaterial());
Assertions.assertEquals(0.3, frontPocket.getMaterialSize());
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/InsidePartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class InsidePartTest {
@Test
public void checkInsidePartConstructor() {

InsidePart insidePart = new InsidePart("Cotton", 5, "black");
InsidePart insidePart = new InsidePart("Cotton", 5, "black", 200);

Assertions.assertEquals("Cotton", insidePart.getMaterial());
Assertions.assertEquals(5, insidePart.getMaterialSize());
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/OutsidePartTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class OutsidePartTest {
public void checkOutsidePartConstructor() {

OutsidePart outsidePart = new OutsidePart("Denim", 5, "blue",
new OutsidePart.Pattern("Round", "Medium", "white"));
new OutsidePart.Pattern("Round", "Medium", "white"), 200);

Assertions.assertEquals("Denim", outsidePart.getMaterial());
Assertions.assertEquals(5, outsidePart.getMaterialSize());
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/PatternTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void testPattern() {
OutsidePart.Pattern pattern = Mockito.mock(OutsidePart.Pattern.class);
pattern.setPattern("Round");
Mockito.when(pattern.getPattern()).thenReturn(str);
OutsidePart outsidePart = new OutsidePart("Denim", 5, "blue", pattern);
OutsidePart outsidePart = new OutsidePart("Denim", 5, "blue", pattern, 200);
Assertions.assertEquals(outsidePart.getPattern().getPattern(), str);
Mockito.verify(pattern).getPattern();
}
Expand Down
2 changes: 1 addition & 1 deletion test/com/Jeans/ZipperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ZipperTest {
@Test
public void checkZipperConstructor() {

Zipper zipper = new Zipper("Steel", 0.1, "black", 0.15);
Zipper zipper = new Zipper("Steel", 0.1, "black", 0.15, 200);

Assertions.assertEquals("Steel", zipper.getMaterial());
Assertions.assertEquals(0.1, zipper.getMaterialSize());
Expand Down