Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions src/main/java/task_1/TimeMachine.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package task_1;

import java.util.Date;

public class TimeMachine {
private int currentYear;
private boolean isWorking;

public static void main(String[] args) {
TimeTraveler timeTraveler1 = new TimeTraveler("Ivan1", 1983, 2080);
TimeTraveler timeTraveler2 = new TimeTraveler("Ivan2", 2000, 2090);
TimeTraveler timeTraveler3 = new TimeTraveler("Ivan3", 1995, 2100);
TimeMachine timeMachine = new TimeMachine();
timeMachine.isWorking=true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ctrl + alt + L в IDEA сделает автоформатирование

timeMachine.traveInTime(timeTraveler1, 2000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Обработки исключения не хватает

// timeMachine.traveInTime(timeTraveler2, 1999);
// timeMachine.traveInTime(timeTraveler3, 2101);
// timeMachine.traveInTime(timeTraveler1, 2100);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Никогда не коммитим закомментированный код. Его всегда удаляем сразу

}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отступ между методами

public void traveInTime(TimeTraveler timeTraveler, int year) {
if (!isWorking) {
throw new TimeTravelException("Machine is not working");
}
if (year<timeTraveler.getBirthYear()) {
throw new TimeTravelException("Trave in year were traveler not birth");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавить контекст ошибки

}
if (year>timeTraveler.getDearthYear()) {
throw new TimeTravelException("Trave in year were traveler is dead");
}
System.out.println("Trave " + timeTraveler.getName() + "to " + year + " year");
}
}
7 changes: 7 additions & 0 deletions src/main/java/task_1/TimeTravelException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package task_1;

public class TimeTravelException extends RuntimeException {
public TimeTravelException(String message) {
super(message);
}
}
39 changes: 39 additions & 0 deletions src/main/java/task_1/TimeTraveler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package task_1;

import java.util.Date;

public class TimeTraveler {
private String name;
private int birthYear;
private int dearthYear;

public TimeTraveler(String name, int birthYear, int dearthYear) {
this.name = name;
this.birthYear = birthYear;
this.dearthYear = dearthYear;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если не используем, то можно и удалить в принципе


public int getBirthYear() {
return birthYear;
}

public void setBirthYear(int birthYear) {
this.birthYear = birthYear;
}

public int getDearthYear() {
return dearthYear;
}

public void setDearthYear(int dearthYear) {
this.dearthYear = dearthYear;
}
}