-
Notifications
You must be signed in to change notification settings - Fork 17
Попытался сделать. Явно получилось не так как надо, во втором задании… #22
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
dmithorzh
wants to merge
4
commits into
iaulitin:master
Choose a base branch
from
dmithorzh:master
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
77daf98
Попытался сделать. Явно получилось не так как надо, во втором задании…
dmithorzh d59ae81
Косяки поправил
dmithorzh c602162
Исправил ошибки в старом дз, для выполнения второй части дз пришлось …
dmithorzh fb5e5d2
Create presentationlink
dmithorzh 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 |
|---|---|---|
|
|
@@ -2,4 +2,5 @@ | |
| .idea | ||
| *.iws | ||
| *.iml | ||
| *.ipr | ||
| *.ipr | ||
| /out/ | ||
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
119 changes: 119 additions & 0 deletions
119
src/ru/milandr/courses/complexnumber/tkhorzhevskiy/ComplexNumber.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,119 @@ | ||
| package ru.milandr.courses.complexnumber.tkhorzhevskiy; | ||
|
|
||
| import ru.milandr.courses.complexnumber.ComplexNumberInterface; | ||
|
|
||
| public class ComplexNumber implements ComplexNumberInterface { | ||
|
|
||
|
|
||
| protected double real; | ||
| protected double imaginary; | ||
|
|
||
|
|
||
|
|
||
| public ComplexNumber (double x, double y) { | ||
| this.real = x; | ||
| this.imaginary = y; | ||
| } | ||
| @Override | ||
| public double getReal() { | ||
| return this.real; | ||
| } | ||
| public void setReal(double real) { | ||
| this.real = real; | ||
| } | ||
| @Override | ||
| public double getImaginary() { | ||
| return this.imaginary; | ||
| } | ||
| public void setImaginary(double imaginary) { | ||
| this.imaginary = imaginary; | ||
| } | ||
|
|
||
| public void validateNumber(ComplexNumberInterface anotherNumber){ | ||
| if (!(anotherNumber instanceof ComplexNumber)){ | ||
| throw new WrongNumberException("Неверный формат числа"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface add(ComplexNumberInterface anotherNumber) { | ||
| validateNumber(anotherNumber); | ||
| double a = real; | ||
| double b = imaginary; | ||
| double c = anotherNumber.getReal(); | ||
| double d = anotherNumber.getImaginary(); | ||
| return new ComplexNumber((a + c), (b + d)); | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface subtract(ComplexNumberInterface anotherNumber) { | ||
| validateNumber(anotherNumber); | ||
| double a = real; | ||
| double b = imaginary; | ||
| double c = anotherNumber.getReal(); | ||
| double d = anotherNumber.getImaginary(); | ||
| return new ComplexNumber((a - c), (b - d)); | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface multiply(ComplexNumberInterface anotherNumber) { | ||
| validateNumber(anotherNumber); | ||
| double a = real; | ||
| double b = imaginary; | ||
| double c = anotherNumber.getReal(); | ||
| double d = anotherNumber.getImaginary(); | ||
|
|
||
| return new ComplexNumber(a * c - b * d, b * c + a * d); | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface divide(ComplexNumberInterface anotherNumber) { | ||
| validateNumber(anotherNumber); | ||
| double a = real; | ||
| double b = imaginary; | ||
| double c = anotherNumber.getReal(); | ||
| double d = anotherNumber.getImaginary(); | ||
| return new ComplexNumber((a * c + b * d) / (c * c + d * d), (b * c - a * d) / (c * c + d * d)); | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface negate() { | ||
| double a = real * -1; | ||
| double b = imaginary * -1; | ||
| return new ComplexNumber(a,b); | ||
| } | ||
|
|
||
| @Override | ||
| public double calculateModulus() { | ||
| double a = real; | ||
| double b = imaginary; | ||
| return Math.sqrt((a*a + b*b)); | ||
| } | ||
|
|
||
| @Override | ||
| public double calculateArgument() { | ||
| return 0; | ||
| //я тупой и не понял этого. | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return real + "+" + imaginary + "i"; | ||
| } | ||
| public static void main(String[] args) { | ||
|
|
||
| ComplexNumber number = new ComplexNumber(2 , 3); | ||
| System.out.println(number + " 1 число"); | ||
| ComplexNumber number2 = new ComplexNumber(1 , 2); | ||
| System.out.println(number2 + " 2 число"); | ||
| System.out.println(number.add(number2) + " их сумма"); | ||
| System.out.println(number.subtract(number2) + " их разность"); | ||
| System.out.println(number.divide(number2)+ " результат деления"); | ||
| System.out.println(number.multiply(number2)+ " результат перемножения"); | ||
| System.out.println(number.negate() + " негатив 1 числа"); | ||
| System.out.println(number.calculateModulus() + " модуль 1 числа"); | ||
| number.add(new WrongNumber()); | ||
|
|
||
| } | ||
|
|
||
| } | ||
53 changes: 53 additions & 0 deletions
53
src/ru/milandr/courses/complexnumber/tkhorzhevskiy/WrongNumber.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,53 @@ | ||
| package ru.milandr.courses.complexnumber.tkhorzhevskiy; | ||
|
|
||
| import ru.milandr.courses.complexnumber.ComplexNumberInterface; | ||
|
|
||
| public class WrongNumber implements ComplexNumberInterface { | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public ComplexNumberInterface add(ComplexNumberInterface anotherNumber) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface subtract(ComplexNumberInterface anotherNumber) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface multiply(ComplexNumberInterface anotherNumber) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface divide(ComplexNumberInterface anotherNumber) { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public ComplexNumberInterface negate() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public double calculateModulus() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public double calculateArgument() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public double getReal() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public double getImaginary() { | ||
| return 0; | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
src/ru/milandr/courses/complexnumber/tkhorzhevskiy/WrongNumberException.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,9 @@ | ||
| package ru.milandr.courses.complexnumber.tkhorzhevskiy; | ||
|
|
||
| public class WrongNumberException extends RuntimeException{ | ||
|
|
||
| public WrongNumberException(String message){ | ||
| super(message); | ||
| } | ||
|
|
||
| } |
37 changes: 37 additions & 0 deletions
37
src/ru/milandr/courses/farm/tkhorzhevskiy/Application.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,37 @@ | ||
| package ru.milandr.courses.farm.tkhorzhevskiy; | ||
|
Owner
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. По всем своим классам автоформатированием пройтись, так не годится |
||
|
|
||
| import ru.milandr.courses.farm.Animal; | ||
| import ru.milandr.courses.farm.Good; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.animals.Chicken; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.animals.Cow; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.animals.Pig; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Egg; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Meat; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Milk; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| Farmer volodya = new Farmer("Володя"); | ||
| Animal cow = new Cow(); | ||
| Animal pig = new Pig(); | ||
| Animal chicken = new Chicken(); | ||
| Good milk = new Milk(); | ||
| Good meat = new Meat(); | ||
| Good egg = new Egg(); | ||
|
|
||
|
|
||
| volodya.petAnAnimal(cow); | ||
| volodya.petAnAnimal(pig); | ||
| volodya.petAnAnimal(chicken); | ||
| volodya.collectGoods(meat); | ||
| volodya.collectGoods(egg); | ||
| volodya.collectGoods(milk); | ||
| volodya.eatProduct(milk); | ||
| volodya.eatProduct(egg); | ||
| volodya.eatProduct(meat); | ||
| milk.goRotten(); | ||
| volodya.eatProduct(milk); | ||
|
|
||
|
|
||
| } | ||
| } | ||
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,54 @@ | ||
| package ru.milandr.courses.farm.tkhorzhevskiy; | ||
|
|
||
|
|
||
| import ru.milandr.courses.farm.Animal; | ||
| import ru.milandr.courses.farm.GenericFarmer; | ||
| import ru.milandr.courses.farm.Good; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Egg; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Meat; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Milk; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.ParentGood; | ||
|
|
||
| public class Farmer implements GenericFarmer { | ||
| private final String name; | ||
|
|
||
|
|
||
| public Farmer(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| @Override | ||
| public void collectGoods(Good good) { | ||
| if (good instanceof Milk) { | ||
| System.out.println(name + " подоил корову"); | ||
| return; | ||
| } | ||
| if (good instanceof Egg) { | ||
| System.out.println(name + " собрал яйцо"); | ||
| return; | ||
| } | ||
| if (good instanceof Meat) { | ||
| System.out.println(name + " зарезал свинью"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void petAnAnimal(Animal animal) { | ||
| System.out.println(name + " погладил " + animal); | ||
| animal.produceSound(); | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void eatProduct(Good good) { | ||
| ParentGood currGood = (ParentGood) good; | ||
| if (currGood.isRotten()) { | ||
| System.out.println("Фу, протухло " + good); | ||
| return; | ||
| } | ||
| System.out.println(name + " употребил " + currGood.getName()); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
23 changes: 23 additions & 0 deletions
23
src/ru/milandr/courses/farm/tkhorzhevskiy/animals/Chicken.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,23 @@ | ||
| package ru.milandr.courses.farm.tkhorzhevskiy.animals; | ||
|
|
||
| import ru.milandr.courses.farm.Good; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Egg; | ||
|
|
||
| public class Chicken extends ParentAnimal { | ||
| private static final String CHICKEN_NAME = "Курица"; | ||
|
|
||
| public Chicken() { | ||
| name = CHICKEN_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public void produceSound() { | ||
| System.out.println("За орду!"); | ||
| } | ||
|
|
||
| @Override | ||
| public Good produceGoods() { | ||
| return new Egg(); | ||
| } | ||
|
|
||
| } |
23 changes: 23 additions & 0 deletions
23
src/ru/milandr/courses/farm/tkhorzhevskiy/animals/Cow.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,23 @@ | ||
| package ru.milandr.courses.farm.tkhorzhevskiy.animals; | ||
|
|
||
| import ru.milandr.courses.farm.Good; | ||
| import ru.milandr.courses.farm.tkhorzhevskiy.goods.Milk; | ||
|
|
||
| public class Cow extends ParentAnimal { | ||
| private static final String COW_NAME = "Корова"; | ||
|
|
||
| public Cow() { | ||
| name = COW_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public void produceSound() { | ||
| System.out.println("Lets get mooooving"); | ||
| } | ||
|
|
||
| @Override | ||
| public Good produceGoods() { | ||
| return new Milk(); | ||
| } | ||
|
|
||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.