-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 3 #4
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
Ekarry
wants to merge
4
commits into
master
Choose a base branch
from
Lesson_3
base: master
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
Lesson 3 #4
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,11 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| public interface Actions { | ||
| void run(); | ||
|
|
||
| void jump(); | ||
|
|
||
| int getRunDistance(); | ||
|
|
||
| int getJumpHeight(); | ||
| } |
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,15 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| public abstract class Barrier { | ||
| private String name; | ||
|
|
||
| public Barrier(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| protected abstract boolean moving(Actions var1); | ||
|
|
||
| public String getName() { | ||
| return this.name; | ||
| } | ||
| } |
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,32 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Cat implements Actions { | ||
| private String name; | ||
| private int runDistance; | ||
| private int jumpHeight; | ||
|
|
||
| public Cat(String name) { | ||
| this.name = name; | ||
| Random rand = new Random(); | ||
| this.runDistance = rand.nextInt(10); | ||
| this.jumpHeight = rand.nextInt(10); | ||
| } | ||
|
|
||
| public void run() { | ||
| System.out.printf("Cat %s is running %d m\n", this.name, this.getRunDistance()); | ||
| } | ||
|
|
||
| public void jump() { | ||
| System.out.printf("Cat %s is jumping %d m\n", this.name, this.getJumpHeight()); | ||
| } | ||
|
|
||
| public int getRunDistance() { | ||
| return this.runDistance; | ||
| } | ||
|
|
||
| public int getJumpHeight() { | ||
| return this.jumpHeight; | ||
| } | ||
| } |
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,32 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Human implements Actions { | ||
| private String name; | ||
| private int runDistance; | ||
| private int jumpHeight; | ||
|
|
||
| public Human(String name) { | ||
| this.name = name; | ||
| Random rand = new Random(); | ||
| this.runDistance = rand.nextInt(10); | ||
| this.jumpHeight = rand.nextInt(10); | ||
| } | ||
|
|
||
| public void run() { | ||
| System.out.printf("Human %s is running %d m\n", this.name, this.getRunDistance()); | ||
| } | ||
|
|
||
| public void jump() { | ||
| System.out.printf("Human %s is jumping %d m\n", this.name, this.getJumpHeight()); | ||
| } | ||
|
|
||
| public int getRunDistance() { | ||
| return this.runDistance; | ||
| } | ||
|
|
||
| public int getJumpHeight() { | ||
| return this.jumpHeight; | ||
| } | ||
| } |
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,47 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class JustDoIt { | ||
| public static void main(String[] args) { | ||
|
|
||
| Barrier[] barriers = new Barrier[6]; | ||
| int i; | ||
| for(i = 0; i < barriers.length; ++i) { | ||
| Random rand = new Random(); | ||
| boolean isRoad = rand.nextBoolean(); | ||
| if (isRoad) { | ||
| barriers[i] = new Road(i + 1 + " is Road"); | ||
| } else { | ||
| barriers[i] = new Wall(i + 1 + " is Wall"); | ||
| } | ||
| } | ||
|
|
||
| for(i = 0; i < generateParticipants().length; ++i) { | ||
| boolean result = true; | ||
|
|
||
| for(int j = 0; j < barriers.length; ++j) { | ||
| result = barriers[j].moving(generateParticipants()[i]); | ||
| if (!result) { | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (result) { | ||
| System.out.println("Success!!"); | ||
| } else { | ||
| System.out.println("Fail and retires from the race!!"); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private static Actions[] generateParticipants() { | ||
| Actions [] actions = new Actions []{ | ||
| new Human("Peter"), | ||
| new Robot("00XX001Z111"), | ||
| new Cat("Luna") | ||
| }; | ||
| return actions; | ||
| } | ||
| } |
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,23 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Road extends Barrier { | ||
| private int length; | ||
|
|
||
| public Road(String name) { | ||
| super(name); | ||
| Random rand = new Random(); | ||
| this.length = rand.nextInt(10); | ||
| } | ||
|
|
||
| public int getLength() { | ||
| return this.length; | ||
| } | ||
|
|
||
| protected boolean moving(Actions actions) { | ||
| System.out.printf("The barrier number %s and it's length: %d m\n", super.getName(), this.length); | ||
| actions.run(); | ||
| return this.getLength() <= actions.getRunDistance(); | ||
| } | ||
| } |
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,32 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Robot implements Actions { | ||
| private String name; | ||
| private int runDistance; | ||
| private int jumpHeight; | ||
|
|
||
| public Robot(String name) { | ||
| this.name = name; | ||
| Random rand = new Random(); | ||
| this.runDistance = rand.nextInt(10); | ||
| this.jumpHeight = rand.nextInt(10); | ||
| } | ||
|
|
||
| public void run() { | ||
| System.out.printf("Robot %s is running %d m\n", this.name, this.getRunDistance()); | ||
| } | ||
|
|
||
| public void jump() { | ||
| System.out.printf("Robot %s is jumping %d m\n", this.name, this.getJumpHeight()); | ||
| } | ||
|
|
||
| public int getRunDistance() { | ||
| return this.runDistance; | ||
| } | ||
|
|
||
| public int getJumpHeight() { | ||
| return this.jumpHeight; | ||
| } | ||
| } |
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,23 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_1; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Wall extends Barrier { | ||
| private int heigth; | ||
|
|
||
| public Wall(String name) { | ||
| super(name); | ||
| Random rand = new Random(); | ||
| this.heigth = rand.nextInt(10); | ||
| } | ||
|
|
||
| public int getHeigth() { | ||
| return this.heigth; | ||
| } | ||
|
|
||
| protected boolean moving(Actions actions) { | ||
| System.out.printf("The barrier number %s and it's height: %d m\n", super.getName(), this.heigth); | ||
| actions.jump(); | ||
| return this.getHeigth() <= actions.getJumpHeight(); | ||
| } | ||
| } |
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,53 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_2; | ||
|
|
||
|
|
||
| public class ArrayCheck { | ||
| public static void main(String[] args) { | ||
| String[][] strDataWrong = { | ||
| {"1", "2", "3", "4"}, | ||
| {"2", "2", "7", "3"}, | ||
| {"1", "seven", "2", "2"}, | ||
| {"2", "2", "2", "2"} | ||
|
|
||
| }; | ||
| getArraySum(strDataWrong); | ||
|
|
||
| String[][] strSizeWrong = { | ||
| {"1", "2", "3", "4"}, | ||
| {"2", "2", "7", "3"}, | ||
| {"1", "5", "2", "2"}, | ||
| {"2", "2", "2", "2"}, | ||
| {"2", "2", "2", "2"} | ||
|
|
||
| }; | ||
| getArraySum(strSizeWrong); | ||
|
|
||
| } | ||
|
|
||
| private static void getArraySum(String[][] str) { | ||
| if (str.length != 4) { | ||
| throw new MyArraySizeException(); | ||
| } | ||
| for (int i = 0; i < str.length; i++) { | ||
| int sum = 0; | ||
| { | ||
| for (int j = 0; j < str[i].length; j++) { | ||
| inputDate(str[i][j], i, j); | ||
| sum += Integer.parseInt(str[i][j]); | ||
| } | ||
| } | ||
| System.out.println("Результат: "); | ||
| System.out.println(sum); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| private static void inputDate(String str, int x, int y) { | ||
| for (int i = 1; i < str.length(); i++) { | ||
| if (str.charAt(i) < '0' || str.charAt(i) > '9') { | ||
| throw new MyArrayDataException(x+1, y+1); | ||
| } | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/ru/gb/Dmitrieva/HomeWorkApp/Lesson_2/MyArrayDataException.java
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,7 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_2; | ||
|
|
||
| public class MyArrayDataException extends NumberFormatException { | ||
| public MyArrayDataException(int i, int j){ | ||
| super("Не удалось преобразовать элемент массива к числу. В ячейке (" + i + "," + j + ") не цифра."); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/ru/gb/Dmitrieva/HomeWorkApp/Lesson_2/MyArraySizeException.java
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,7 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_2; | ||
|
|
||
| public class MyArraySizeException extends ArrayIndexOutOfBoundsException { | ||
| public MyArraySizeException(){ | ||
| super("Массив не формата 4х4"); | ||
| } | ||
| } |
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,7 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_3; | ||
|
|
||
| public class Apple extends Fruit{ | ||
| public Apple() { | ||
| weight = 1.0; | ||
| } | ||
| } |
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,30 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_3; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| public class Box<T extends Fruit> { | ||
| private ArrayList<T> fruitList = new ArrayList<>(); | ||
|
|
||
| public void addFruit(T fruit){ | ||
| this.fruitList.add(fruit); | ||
| if (fruitList.isEmpty()); | ||
| } | ||
|
|
||
| public double getWeight(){ | ||
| int count = fruitList.size(); | ||
| if (count==0) | ||
| return 0; | ||
| return fruitList.get(0).getWeight()*count; | ||
| } | ||
|
|
||
| public boolean compare(Box box){ | ||
| return this.getWeight()==box.getWeight(); | ||
| } | ||
|
|
||
| public void pourOverTo(Box<T> destBox){ | ||
| for (T fruit : fruitList){ | ||
| destBox.addFruit(fruit); | ||
| } | ||
| fruitList.clear(); | ||
| } | ||
| } | ||
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,9 @@ | ||
| package ru.gb.Dmitrieva.HomeWorkApp.Lesson_3; | ||
|
|
||
| public abstract class Fruit { | ||
| double weight; | ||
|
|
||
| public double getWeight(){ | ||
| return weight; | ||
| }; | ||
| } |
Oops, something went wrong.
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.
тут снова баг о котором я говорил на разборе ДЗ