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
2 changes: 1 addition & 1 deletion .github/linters/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<module name="Checker">


<!-- Checks that property files contain the same keys. -->
<!-- Checks that property files contain the same keys..-->
<module name="Translation"/>

<!-- Checks that no tab characters in the source code. -->
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/flower/store/Flower.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import lombok.Getter;
import lombok.Setter;



@Setter
public class Flower {
@Getter
Expand All @@ -15,6 +13,23 @@ public class Flower {
@Getter
private FlowerType flowerType;

// No-argument constructor
public Flower() {
// You can initialize default values if needed
this.flowerType = FlowerType.DEFAULT_TYPE;
this.price = 0.0;
this.sepalLength = 0.0;
this.color = FlowerColor.DEFAULT_COLOR;
}

// Copy constructor
public Flower(Flower flower) {
this.flowerType = flower.flowerType;
this.price = flower.price;
this.sepalLength = flower.sepalLength;
this.color = flower.color;
}

public String getColor() {
return color.toString();
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/flower/store/FlowerBucket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package flower.store;

import java.util.ArrayList;
import java.util.List;

public class FlowerBucket extends Item {
private List<FlowerPack> flowerPacks = new ArrayList<>();

public double getPrice() {
double price = 0;
for (FlowerPack flowerPack : flowerPacks) {
price += flowerPack.getPrice();
}
return price;
}

public void addFlowerPack(FlowerPack flowerPack) {
flowerPacks.add(flowerPack);
}
}
2 changes: 1 addition & 1 deletion src/main/java/flower/store/FlowerColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public enum FlowerColor {
/**
* Flower colors.
*/
RED("#FF0000"), BLUE("#0000FF");
RED("#FF0000"), BLUE("#0000FF"), DEFAULT_COLOR("00000");
private final String stringRepresentation;

FlowerColor(String stringRepresentation) {
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/flower/store/FlowerPack.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package flower.store;

import lombok.Setter;

@Setter
public class FlowerPack {
private Flower flower;
private int quantity;
}
private int amount;

public FlowerPack(Flower flower, int amount) {
this.flower = new Flower(flower);
this.amount = amount;
}

public double getPrice() {
return flower.getPrice() * amount;
}
}
4 changes: 3 additions & 1 deletion src/main/java/flower/store/FlowerType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package flower.store;

public enum FlowerType {
CHAMOMILE, ROSE, TULIP;
CHAMOMILE, ROSE, TULIP,
DEFAULT_TYPE; // Default value

}
5 changes: 5 additions & 0 deletions src/main/java/flower/store/Item.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package flower.store;

public abstract class Item {
public abstract double getPrice();
}
6 changes: 6 additions & 0 deletions src/main/java/flower/store/SearchFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package flower.store;


public interface SearchFilter {
boolean match(Item item);
}
19 changes: 19 additions & 0 deletions src/main/java/flower/store/Store.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package flower.store;

import java.util.ArrayList;
import java.util.List;


public class Store {
private List<Item> items;
public List<Item> search(SearchFilter filter) {
List<Item> foundItems = new ArrayList<>();
for (Item item: items) {
if (filter.match(item)) {
foundItems.add(item);
}
}
return foundItems;
}

}
33 changes: 33 additions & 0 deletions src/test/java/flower/store/FlowerBucketTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package flower.store;


import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

import java.util.Random;

public class FlowerBucketTest {
private static final Random RANDOM_GENERATOR = new Random();
private static final int MAX_QUANTITY = 1000;
private static final int MAX_PRICE = 100;

private FlowerBucket flowerBucket;

@BeforeEach
public void init() {
flowerBucket = new FlowerBucket();
}

@Test
public void testPrice() {
int price = RANDOM_GENERATOR.nextInt(MAX_PRICE);
int quantity = RANDOM_GENERATOR.nextInt(MAX_QUANTITY);
Flower flower = new Flower();
flower.setFlowerType(FlowerType.ROSE);
flower.setPrice(price);
FlowerPack flowerPack = new FlowerPack(flower, quantity);
flowerBucket.addFlowerPack(flowerPack);
Assertions.assertEquals(price * quantity, flowerBucket.getPrice());
}
}
48 changes: 48 additions & 0 deletions src/test/java/flower/store/FlowerPackTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package flower.store;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;

public class FlowerPackTest {
private Flower flower;
private FlowerPack flowerPack;

private final double vall = 10;
private final double valk = 5;
private final double delta = 0.001;



@BeforeEach
public void init() {
// Create a flower object with specific attributes
flower = new Flower();
flower.setPrice(vall); // Set price per flower
flower.setSepalLength(valk);
flower.setFlowerType(FlowerType.ROSE);
flower.setColor(FlowerColor.RED);

// Create a flower pack with 5 flowers
flowerPack = new FlowerPack(flower, (int) valk);
}

@Test
public void testGetPrice() {
// Test if the price is calculated correctly
double expectedPrice = vall * valk; // Price per flower * amount
Assertions.assertEquals(expectedPrice, flowerPack.getPrice(),
delta, "Price calculation failed");
}

@Test
public void testSetAmount() {
// Change the amount of flowers in the pack
flowerPack.setAmount((int) vall);

// Test if the new price reflects the updated amount
double expectedPrice = vall * vall; // Price per flower * new amount
Assertions.assertEquals(expectedPrice, flowerPack.getPrice(),
delta,
"Updated price calculation failed");
}
}