-
Notifications
You must be signed in to change notification settings - Fork 12
task1 is done #15
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 is done #15
Changes from 1 commit
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,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; | ||
| timeMachine.traveInTime(timeTraveler1, 2000); | ||
|
||
| // timeMachine.traveInTime(timeTraveler2, 1999); | ||
| // timeMachine.traveInTime(timeTraveler3, 2101); | ||
| // timeMachine.traveInTime(timeTraveler1, 2100); | ||
|
||
| } | ||
|
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. Отступ между методами |
||
| 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"); | ||
|
||
| } | ||
| if (year>timeTraveler.getDearthYear()) { | ||
| throw new TimeTravelException("Trave in year were traveler is dead"); | ||
| } | ||
| System.out.println("Trave " + timeTraveler.getName() + "to " + year + " year"); | ||
| } | ||
| } | ||
| 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); | ||
| } | ||
| } |
| 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; | ||
| } | ||
|
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. Если не используем, то можно и удалить в принципе |
||
|
|
||
| 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; | ||
| } | ||
| } | ||
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.
ctrl + alt + L в IDEA сделает автоформатирование