-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 6 homework done #6
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
Open
Scrag87
wants to merge
1
commit into
CoffeeMachine_OOP
Choose a base branch
from
lesson6
base: CoffeeMachine_OOP
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package java_core.lesson6.homework; | ||
|
||
import java_core.lesson6.homework.Animals.Cat; | ||
|
||
public class Animal { | ||
|
||
protected String name; | ||
protected Double jumpLimit; | ||
protected int swimLimit; | ||
protected int runLimit; | ||
|
||
public Animal(String name, Double jumpLimit, int swimLimit, int runLimit) { | ||
this.name = name; | ||
this.jumpLimit = jumpLimit; | ||
this.swimLimit = swimLimit; | ||
this.runLimit = runLimit; | ||
} | ||
|
||
public void run(int runDistance) { | ||
System.out.print(this.name + " "); | ||
if (runDistance <= runLimit) { | ||
System.out.println("run: true" + "(limit is " + this.runLimit + " && command is " + runDistance + ")"); | ||
runLimit -= runDistance; | ||
|
||
} else System.out.println("run: false" + "(limit is " + this.runLimit + " but command is " + runDistance + ")"); | ||
} | ||
|
||
public void swim(int swimDistance) { | ||
System.out.print(this.name + " "); | ||
if (swimDistance <= swimLimit) { | ||
System.out.println("swim: true" + "(limit is " + this.swimLimit + " && command is " + swimDistance + ")"); | ||
swimLimit -= swimDistance; | ||
} else | ||
System.out.println("swim: false" + "(limit is " + this.swimLimit + " but command is " + swimDistance + ")"); | ||
} | ||
|
||
public void jump(Double jumpDistance) { | ||
System.out.print(this.name + " "); | ||
if (jumpDistance <= jumpLimit) { | ||
System.out.println("jump: true" + "(limit is " + this.jumpLimit + " && command is " + jumpDistance + ")"); | ||
jumpLimit -= jumpDistance; | ||
} else | ||
System.out.println("jump: false" + "(limit is " + this.jumpLimit + " but command is " + jumpDistance + ")"); | ||
|
||
} | ||
|
||
public void rest(int minutes) { | ||
System.out.println(); | ||
System.out.println("ZZZzzz " + this.name + " is rested for: " + minutes); | ||
System.out.println(); | ||
this.jumpLimit += minutes; | ||
this.runLimit += minutes * 2; | ||
if (this.getClass().equals(Cat.class)) this.swimLimit = 0; //как вариант. не стал переопределять в классе | ||
else this.swimLimit += minutes; | ||
} | ||
|
||
public void printLimits() { | ||
System.out.println(); | ||
System.out.println(this.name + " JumpLimit is: " + this.jumpLimit); | ||
System.out.println(this.name + " SwimLimit is: " + this.swimLimit); | ||
System.out.println(this.name + " RunLimit is: " + this.runLimit); | ||
System.out.println(); | ||
} | ||
|
||
public void printResult() { | ||
|
||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package java_core.lesson6.homework.Animals; | ||
|
||
import java_core.lesson6.homework.Animal; | ||
|
||
public class Cat extends Animal { | ||
|
||
public Cat(String name, Double jumpLimit, int swimLimit, int runLimit) { | ||
super(name, jumpLimit, swimLimit, runLimit); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package java_core.lesson6.homework.Animals; | ||
|
||
import java_core.lesson6.homework.Animal; | ||
|
||
public class Dog extends Animal { | ||
|
||
public Dog(String name, Double jumpLimit, int swimLimit, int runLimit) { | ||
super(name, jumpLimit, swimLimit, runLimit); | ||
} | ||
|
||
@Override | ||
public void rest(int minutes) { | ||
System.out.println("ZZZzzz " + this.name + " is rested for: " + minutes); | ||
this.jumpLimit += minutes; | ||
this.runLimit += minutes * 3; | ||
this.swimLimit += minutes; | ||
|
||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package java_core.lesson6.homework.Animals; | ||
|
||
import java_core.lesson6.homework.Animal; | ||
|
||
public class Horse extends Animal { | ||
|
||
|
||
public Horse(String name, Double jumpLimit, int swimLimit, int runLimit) { | ||
super(name, jumpLimit, swimLimit, runLimit); | ||
} | ||
|
||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package java_core.lesson6.homework.Animals; | ||
|
||
public class Hound extends Dog { | ||
public Hound(String name, Double jumpLimit, int swimLimit, int runLimit) { | ||
super(name, jumpLimit, swimLimit, runLimit); | ||
} | ||
|
||
@Override | ||
public void rest(int minutes) { | ||
System.out.println("ZZZzzz " + this.name + " is rested for: " + minutes); | ||
this.jumpLimit += minutes; | ||
this.runLimit += minutes * 5; | ||
this.swimLimit += minutes; | ||
|
||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package java_core.lesson6.homework; | ||
|
||
import java_core.lesson6.homework.Animals.Cat; | ||
import java_core.lesson6.homework.Animals.Dog; | ||
import java_core.lesson6.homework.Animals.Hound; | ||
|
||
public class Main { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
Animal cat = new Cat("Kitty", 0.5, 0, 200); | ||
Animal cat2 = new Cat("Suzi", 2., 0, 300); | ||
Animal dog = new Dog("Bobik", 0.5, 10, 500); | ||
Animal hound = new Hound("Pushok", 1., 5, 500); | ||
|
||
cat.jump(0.2); | ||
cat.jump(0.2); | ||
cat.printLimits(); | ||
cat.rest(20); | ||
cat.printLimits(); | ||
cat.swim(2); | ||
cat.jump(0.2); | ||
|
||
cat2.run(101); | ||
cat2.run(100); | ||
cat2.rest(5); | ||
cat2.run(100); | ||
|
||
dog.run(200); | ||
dog.run(200); | ||
dog.printLimits(); | ||
dog.rest(20); | ||
dog.printLimits(); | ||
dog.swim(20); | ||
dog.swim(20); | ||
dog.swim(20); | ||
dog.run(200); | ||
|
||
hound.printLimits(); | ||
hound.rest(30); | ||
hound.printLimits(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.