diff --git a/build/classes/java/main/task_1/solution/Main.class b/build/classes/java/main/task_1/solution/Main.class new file mode 100644 index 0000000..0c7e5c0 Binary files /dev/null and b/build/classes/java/main/task_1/solution/Main.class differ diff --git a/build/classes/java/main/task_1/solution/TimeMachine.class b/build/classes/java/main/task_1/solution/TimeMachine.class new file mode 100644 index 0000000..f910414 Binary files /dev/null and b/build/classes/java/main/task_1/solution/TimeMachine.class differ diff --git a/build/classes/java/main/task_1/solution/TimeTravelException.class b/build/classes/java/main/task_1/solution/TimeTravelException.class new file mode 100644 index 0000000..c531cd2 Binary files /dev/null and b/build/classes/java/main/task_1/solution/TimeTravelException.class differ diff --git a/build/classes/java/main/task_1/solution/TimeTraveler.class b/build/classes/java/main/task_1/solution/TimeTraveler.class new file mode 100644 index 0000000..f69aba0 Binary files /dev/null and b/build/classes/java/main/task_1/solution/TimeTraveler.class differ diff --git a/build/classes/java/main/task_2/solution/Main.class b/build/classes/java/main/task_2/solution/Main.class new file mode 100644 index 0000000..0cf7e4d Binary files /dev/null and b/build/classes/java/main/task_2/solution/Main.class differ diff --git a/build/classes/java/main/task_2/solution/OlivandersShop.class b/build/classes/java/main/task_2/solution/OlivandersShop.class new file mode 100644 index 0000000..6cc792c Binary files /dev/null and b/build/classes/java/main/task_2/solution/OlivandersShop.class differ diff --git a/build/classes/java/main/task_2/solution/Wand.class b/build/classes/java/main/task_2/solution/Wand.class new file mode 100644 index 0000000..3b7399e Binary files /dev/null and b/build/classes/java/main/task_2/solution/Wand.class differ diff --git a/build/classes/java/main/task_2/solution/WandOrder.class b/build/classes/java/main/task_2/solution/WandOrder.class new file mode 100644 index 0000000..8c83e3d Binary files /dev/null and b/build/classes/java/main/task_2/solution/WandOrder.class differ diff --git a/build/classes/java/main/task_2/solution/exceptions/NoOrdersException.class b/build/classes/java/main/task_2/solution/exceptions/NoOrdersException.class new file mode 100644 index 0000000..d21c83d Binary files /dev/null and b/build/classes/java/main/task_2/solution/exceptions/NoOrdersException.class differ diff --git a/build/classes/java/main/task_2/solution/exceptions/NotEnoughMaterialException.class b/build/classes/java/main/task_2/solution/exceptions/NotEnoughMaterialException.class new file mode 100644 index 0000000..e3a6767 Binary files /dev/null and b/build/classes/java/main/task_2/solution/exceptions/NotEnoughMaterialException.class differ diff --git a/build/classes/java/main/task_2/solution/exceptions/NotEnoughWoodException.class b/build/classes/java/main/task_2/solution/exceptions/NotEnoughWoodException.class new file mode 100644 index 0000000..bb12d2a Binary files /dev/null and b/build/classes/java/main/task_2/solution/exceptions/NotEnoughWoodException.class differ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 0000000..3e66411 Binary files /dev/null and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/task_1/solution/Main.java b/src/main/java/task_1/solution/Main.java new file mode 100644 index 0000000..1514718 --- /dev/null +++ b/src/main/java/task_1/solution/Main.java @@ -0,0 +1,17 @@ +package task_1.solution; + +public class Main { + public static void main(String[] args) { + TimeMachine timeMachine = new TimeMachine(2023); + + TimeTraveler traveler1 = new TimeTraveler("Travis", 1990, 2100); + TimeTraveler traveler2 = new TimeTraveler("Ja", 1985, 2050); + + try { + timeMachine.travelInTime(traveler1, 2000); + timeMachine.travelInTime(traveler2, 2075); + } catch (TimeTravelException e) { + System.out.println("Произошла ошибка: " + e.getMessage()); + } + } +} diff --git a/src/main/java/task_1/solution/TimeMachine.java b/src/main/java/task_1/solution/TimeMachine.java new file mode 100644 index 0000000..0f70941 --- /dev/null +++ b/src/main/java/task_1/solution/TimeMachine.java @@ -0,0 +1,29 @@ +package task_1.solution; + +public class TimeMachine { + private int currentYear; + private boolean isWorking; + + public TimeMachine(int currentYear) { + this.currentYear = currentYear; + this.isWorking = true; + } + + public void travelInTime(TimeTraveler timeTraveler, int year) throws TimeTravelException { + if (!isWorking) { + throw new TimeTravelException("The time machine is not working at the moment."); + } + + if (year < timeTraveler.getBirthYear()) { + throw new TimeTravelException("The year of travel to the past is less than the year of the traveler's " + + "birth."); + } + + if (year > timeTraveler.getDeathYear()) { + throw new TimeTravelException("The year of the travel into the future is longer than the year of the " + + "traveler's death."); + } + + System.out.println(timeTraveler.getName() + " travels through time in " + year + " year."); + } +} diff --git a/src/main/java/task_1/solution/TimeTravelException.java b/src/main/java/task_1/solution/TimeTravelException.java new file mode 100644 index 0000000..9e8bad4 --- /dev/null +++ b/src/main/java/task_1/solution/TimeTravelException.java @@ -0,0 +1,7 @@ +package task_1.solution; + +public class TimeTravelException extends Exception { + public TimeTravelException(String message) { + super(message); + } +} diff --git a/src/main/java/task_1/solution/TimeTraveler.java b/src/main/java/task_1/solution/TimeTraveler.java new file mode 100644 index 0000000..0571b89 --- /dev/null +++ b/src/main/java/task_1/solution/TimeTraveler.java @@ -0,0 +1,25 @@ +package task_1.solution; + +public class TimeTraveler { + private String name; + private int birthYear; + private int deathYear; + + public TimeTraveler(String name, int birthYear, int deathYear) { + this.name = name; + this.birthYear = birthYear; + this.deathYear = deathYear; + } + + public String getName() { + return name; + } + + public int getBirthYear() { + return birthYear; + } + + public int getDeathYear() { + return deathYear; + } +} diff --git a/src/main/java/task_2/solution/Main.java b/src/main/java/task_2/solution/Main.java new file mode 100644 index 0000000..aca0b18 --- /dev/null +++ b/src/main/java/task_2/solution/Main.java @@ -0,0 +1,26 @@ +package task_2.solution; + +import task_2.solution.exceptions.NoOrdersException; +import task_2.solution.exceptions.NotEnoughMaterialException; +import task_2.solution.exceptions.NotEnoughWoodException; + +public class Main { + public static void main(String[] args) { + try { + Wand wand1 = new Wand("Дуб", 12, "-", 10); + WandOrder order1 = new WandOrder("Петр", wand1, 3); + + Wand wand2 = new Wand("Ель", 11, "-", 12); + WandOrder order2 = new WandOrder("Шавкат", wand2, 2); + + OlivandersShop olivanders = new OlivandersShop(); + olivanders.placeOrder(order1); + olivanders.placeOrder(order2); + + Wand mostPowerfulWand = olivanders.findMostPowerfulWand(); + System.out.println("Самая сильная палочка : " + mostPowerfulWand.getWoodType() + " " + mostPowerfulWand.getCoreMaterial()); + } catch (NotEnoughWoodException | NotEnoughMaterialException | NoOrdersException e) { + System.out.println("Ошибка: " + e.getMessage()); + } + } +} diff --git a/src/main/java/task_2/solution/OlivandersShop.java b/src/main/java/task_2/solution/OlivandersShop.java new file mode 100644 index 0000000..f83f0b0 --- /dev/null +++ b/src/main/java/task_2/solution/OlivandersShop.java @@ -0,0 +1,68 @@ +package task_2.solution; + +import task_2.solution.exceptions.NoOrdersException; +import task_2.solution.exceptions.NotEnoughMaterialException; +import task_2.solution.exceptions.NotEnoughWoodException; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class OlivandersShop { + private List orders; + private Map woodTypeCount; + private Map coreMaterialCount; + + public OlivandersShop() { + orders = new ArrayList<>(); + woodTypeCount = new HashMap<>(); + coreMaterialCount = new HashMap<>(); + } + public void placeOrder(WandOrder order) throws NotEnoughMaterialException, NotEnoughWoodException { + String woodType = order.getWand().getWoodType(); + int requiredWoodCount = order.getQuantity(); + + if (woodTypeCount.containsKey(woodType)) { + int availableWoodCount = woodTypeCount.get(woodType); + if (availableWoodCount < requiredWoodCount) { + throw new NotEnoughWoodException(woodType); + } + woodTypeCount.put(woodType, availableWoodCount - requiredWoodCount); + } else { + throw new NotEnoughWoodException(woodType); + } + + String coreMaterial = order.getWand().getCoreMaterial(); + int requiredMaterialCount = order.getQuantity(); + + if (coreMaterialCount.containsKey(coreMaterial)) { + int availableMaterialCount = coreMaterialCount.get(coreMaterial); + if (availableMaterialCount < requiredMaterialCount) { + throw new NotEnoughMaterialException(coreMaterial); + } + coreMaterialCount.put(coreMaterial, availableMaterialCount - requiredMaterialCount); + } else { + throw new NotEnoughMaterialException(coreMaterial); + } + + orders.add(order); + } + public Wand findMostPowerfulWand() throws NoOrdersException{ + if (orders.isEmpty()) { + throw new NoOrdersException("Заказы недоступны"); + } + + Wand mostPowerfulWand = orders.get(0).getWand(); + int maxPowerLevel = mostPowerfulWand.getPowerLevel(); + + for (WandOrder order : orders) { + if (order.getWand().getPowerLevel() > maxPowerLevel) { + mostPowerfulWand = order.getWand(); + maxPowerLevel = mostPowerfulWand.getPowerLevel(); + } + } + + return mostPowerfulWand; + } +} diff --git a/src/main/java/task_2/solution/Wand.java b/src/main/java/task_2/solution/Wand.java new file mode 100644 index 0000000..67170c1 --- /dev/null +++ b/src/main/java/task_2/solution/Wand.java @@ -0,0 +1,47 @@ +package task_2.solution; + +import task_2.solution.exceptions.NotEnoughMaterialException; +import task_2.solution.exceptions.NotEnoughWoodException; + +public class Wand { + private String woodType; + private double length; + private String coreMaterial; + private int powerLevel; + + public Wand(String woodType, int length, String coreMaterial, int powerLevel) throws NotEnoughWoodException, + NotEnoughMaterialException { + if (woodType == null || woodType.isEmpty()) { + throw new NotEnoughWoodException("Тип дерева не может быть пустым"); + } + if (length <= 0) { + throw new IllegalArgumentException("Длина должна быть больше 0"); + } + if (coreMaterial == null || coreMaterial.isEmpty()) { + throw new NotEnoughMaterialException("Материал не может быть пустым"); + } + if (powerLevel <= 0) { + throw new IllegalArgumentException("Уровень мощности должен быть больше 0"); + } + this.woodType = woodType; + this.length = length; + this.coreMaterial = coreMaterial; + this.powerLevel = powerLevel; + } + + public String getWoodType() { + return woodType; + } + + public double getLength() { + return length; + } + + public String getCoreMaterial() { + return coreMaterial; + } + + public int getPowerLevel() { + return powerLevel; + } +} diff --git a/src/main/java/task_2/solution/WandOrder.java b/src/main/java/task_2/solution/WandOrder.java new file mode 100644 index 0000000..0194987 --- /dev/null +++ b/src/main/java/task_2/solution/WandOrder.java @@ -0,0 +1,31 @@ +package task_2.solution; + +public class WandOrder { + private String customerName; + private Wand wand; + private int quantity; + public WandOrder(String customerName, Wand wand, int quantity) { + if (customerName == null || customerName.isEmpty()) { + throw new IllegalArgumentException("Имя клиента не может быть пустым"); + } + if (quantity <= 0) { + throw new IllegalArgumentException("Количество должно быть больше 0"); + } + + this.customerName = customerName; + this.wand = wand; + this.quantity = quantity; + } + + public String getCustomerName() { + return customerName; + } + + public Wand getWand() { + return wand; + } + + public int getQuantity() { + return quantity; + } +} diff --git a/src/main/java/task_2/solution/exceptions/NoOrdersException.java b/src/main/java/task_2/solution/exceptions/NoOrdersException.java new file mode 100644 index 0000000..1158b11 --- /dev/null +++ b/src/main/java/task_2/solution/exceptions/NoOrdersException.java @@ -0,0 +1,7 @@ +package task_2.solution.exceptions; + +public class NoOrdersException extends Exception{ + public NoOrdersException(String message) { + super(message); + } +} diff --git a/src/main/java/task_2/solution/exceptions/NotEnoughMaterialException.java b/src/main/java/task_2/solution/exceptions/NotEnoughMaterialException.java new file mode 100644 index 0000000..14230a5 --- /dev/null +++ b/src/main/java/task_2/solution/exceptions/NotEnoughMaterialException.java @@ -0,0 +1,7 @@ +package task_2.solution.exceptions; + +public class NotEnoughMaterialException extends Exception{ + public NotEnoughMaterialException(String material) { + super("Недостаточно материала для сердца палочки: " + material); + } +} diff --git a/src/main/java/task_2/solution/exceptions/NotEnoughWoodException.java b/src/main/java/task_2/solution/exceptions/NotEnoughWoodException.java new file mode 100644 index 0000000..67f3dea --- /dev/null +++ b/src/main/java/task_2/solution/exceptions/NotEnoughWoodException.java @@ -0,0 +1,7 @@ +package task_2.solution.exceptions; + +public class NotEnoughWoodException extends Exception{ + public NotEnoughWoodException(String woodType) { + super("Недостаточно дерева типа " + woodType + " для изготовления палочек."); + } +}