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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
17 changes: 17 additions & 0 deletions src/main/java/task_1/solution/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
29 changes: 29 additions & 0 deletions src/main/java/task_1/solution/TimeMachine.java
Original file line number Diff line number Diff line change
@@ -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.");
}
}
7 changes: 7 additions & 0 deletions src/main/java/task_1/solution/TimeTravelException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package task_1.solution;

public class TimeTravelException extends Exception {
public TimeTravelException(String message) {
super(message);
}
}
25 changes: 25 additions & 0 deletions src/main/java/task_1/solution/TimeTraveler.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 26 additions & 0 deletions src/main/java/task_2/solution/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
68 changes: 68 additions & 0 deletions src/main/java/task_2/solution/OlivandersShop.java
Original file line number Diff line number Diff line change
@@ -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<WandOrder> orders;
private Map<String, Integer> woodTypeCount;
private Map<String, Integer> 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;
}
}
47 changes: 47 additions & 0 deletions src/main/java/task_2/solution/Wand.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
31 changes: 31 additions & 0 deletions src/main/java/task_2/solution/WandOrder.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package task_2.solution.exceptions;

public class NoOrdersException extends Exception{
public NoOrdersException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package task_2.solution.exceptions;

public class NotEnoughMaterialException extends Exception{
public NotEnoughMaterialException(String material) {
super("Недостаточно материала для сердца палочки: " + material);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package task_2.solution.exceptions;

public class NotEnoughWoodException extends Exception{
public NotEnoughWoodException(String woodType) {
super("Недостаточно дерева типа " + woodType + " для изготовления палочек.");
}
}
31 changes: 31 additions & 0 deletions src/main/java/task_3/solution/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package task_3.solution;

import java.util.List;

public class Main {
public static void main(String[] args){
SimpsonsSchool simpsonsSchool = new SimpsonsSchool();

SimpsonsCharacter bart = new SimpsonsCharacter("Bart", 11, 1);
SimpsonsCharacter lisa = new SimpsonsCharacter("Lisa", 9, 2);

SimpsonsCourse math = new SimpsonsCourse("Math", 1);
SimpsonsCourse barts_pranks = new SimpsonsCourse("Bart's Pranks", 2);
SimpsonsCourse history = new SimpsonsCourse("History", 3);

simpsonsSchool.enrollCharacter(bart, List.of(math, barts_pranks));
simpsonsSchool.enrollCharacter(lisa, List.of(math, history, barts_pranks));

try {
simpsonsSchool.addGrade(bart, math, 4);
simpsonsSchool.addGrade(bart, history, 3);
simpsonsSchool.addGrade(bart, barts_pranks, 5);

simpsonsSchool.addGrade(lisa, math, 5);
simpsonsSchool.addGrade(lisa, history, 4);
simpsonsSchool.addGrade(lisa, barts_pranks, 0);
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/task_3/solution/SimpsonsCharacter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package task_3.solution;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SimpsonsCharacter {
private String name;
private int age;
private int characterId;
private List<SimpsonsCourse> enrolledCourses = new ArrayList<>();
private Map<SimpsonsCourse, Integer> grades = new HashMap<>();

public SimpsonsCharacter(String name, int age, int characterId) {
this.name = name;
this.age = age;
this.characterId = characterId;
}

public String getName() {
return name;
}

public int getAge() {
return age;
}

public int getCharacterId() {
return characterId;
}

public List<SimpsonsCourse> getEnrolledCourses() {
return enrolledCourses;
}

public Map<SimpsonsCourse, Integer> getGrades() {
return grades;
}
}
19 changes: 19 additions & 0 deletions src/main/java/task_3/solution/SimpsonsCourse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package task_3.solution;

public class SimpsonsCourse {
private String courseName;
private int courseId;

public SimpsonsCourse(String courseName, int courseId) {
this.courseName = courseName;
this.courseId = courseId;
}

public String getCourseName() {
return courseName;
}

public int getCourseId() {
return courseId;
}
}
Loading