-
Notifications
You must be signed in to change notification settings - Fork 12
task1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
task1 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не логируется stacktrace |
||
| } | ||
| } | ||
| } | ||
| 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."); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Добавить информацию о путешественнике во времени |
||
| } | ||
|
|
||
| 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."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package task_1.solution; | ||
|
|
||
| public class TimeTravelException extends Exception { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше unchecked |
||
| public TimeTravelException(String message) { | ||
| super(message); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package task_1.solution; | ||
|
|
||
| public class TimeTraveler { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Рассмотреть использования lombok |
||
| 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; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slf4j из lombok даст log объект