generated from mate-academy/jv-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Realization of full application #1280
Open
forzen123212
wants to merge
12
commits into
mate-academy:master
Choose a base branch
from
forzen123212:ForzenBranch
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
12 commits
Select commit
Hold shift + click to select a range
b7ef090
Realization of full application
forzen123212 515b89f
Realization of full application
forzen123212 cae4fac
Merge remote-tracking branch 'origin/ForzenBranch' into ForzenBranch
forzen123212 51c56c3
Realization of full application
forzen123212 5e19cc3
Realization of full application
forzen123212 7fa69f2
Realization of full application
forzen123212 24686a8
Merge remote-tracking branch 'origin/ForzenBranch' into ForzenBranch
forzen123212 cd42fa0
Realization of full application
forzen123212 a50dbd1
Fixed style and main method
forzen123212 f3d8d66
Fixed style and main method
forzen123212 8223f8c
Fixed style and main method
forzen123212 797aaf3
Added fixes
forzen123212 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 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,18 @@ | ||
package core.basesyntax; | ||
|
||
public class Application { | ||
private static final int FIGURE_COUNT = 6; | ||
|
||
public static void main(String[] args) { | ||
FigureSupplier figureSupplier = new FigureSupplier(); | ||
Figure[] figures = new Figure[FIGURE_COUNT]; | ||
for (int i = 0; i < FIGURE_COUNT; i++) { | ||
if (i < FIGURE_COUNT / 2) { | ||
figures[i] = figureSupplier.getRandomFigure(); | ||
} else { | ||
figures[i] = figureSupplier.getDefaultFigure(); | ||
} | ||
figures[i].draw(); | ||
} | ||
} | ||
} |
This file contains 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,5 @@ | ||
package core.basesyntax; | ||
|
||
public interface AreaCalculator { | ||
double getArea(); | ||
} |
This file contains 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 core.basesyntax; | ||
|
||
public class Circle extends Figure { | ||
private final int radius; | ||
|
||
public Circle(int radius, String color) { | ||
super(color); | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return Math.PI * Math.pow(radius, 2); | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: circle, area: " | ||
+ getArea() | ||
+ ", radius: " | ||
+ radius + ", color: " + color); | ||
} | ||
} |
This file contains 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,12 @@ | ||
package core.basesyntax; | ||
|
||
public enum Color { | ||
BLACK, | ||
WHITE, | ||
YELLOW, | ||
GREEN, | ||
BLUE, | ||
ORANGE, | ||
PURPLE, | ||
PINK | ||
} |
This file contains 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 core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
private final Random random = new Random(); | ||
private final Color[] colorArray = Color.values(); | ||
|
||
public String getRandomColor() { | ||
int index = random.nextInt(colorArray.length); | ||
return colorArray[index].name(); | ||
} | ||
} |
This file contains 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,5 @@ | ||
package core.basesyntax; | ||
|
||
public interface Drawable { | ||
void draw(); | ||
} |
This file contains 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 core.basesyntax; | ||
|
||
public abstract class Figure implements Drawable, AreaCalculator { | ||
protected String color; | ||
|
||
public Figure(String color) { | ||
this.color = color; | ||
} | ||
|
||
public String getColor() { | ||
return color; | ||
} | ||
} |
This file contains 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,40 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class FigureSupplier { | ||
private static final int MAX_LENGTH = 100; | ||
private static final int FIGURE_COUNT = 5; | ||
private static final int DEFAULT_RADIUS = 10; | ||
private static final String DEFAULT_COLOR = Color.WHITE.name(); | ||
|
||
private final Random random = new Random(); | ||
private final ColorSupplier supplier = new ColorSupplier(); | ||
|
||
public Figure getRandomFigure() { | ||
String color = supplier.getRandomColor(); | ||
final int index = random.nextInt(FIGURE_COUNT); | ||
|
||
switch (index) { | ||
case 0: | ||
return new Circle(getRandomNumber(), color); | ||
case 1: | ||
return new IsoscelesTrapezoid(getRandomNumber(), getRandomNumber(), | ||
getRandomNumber(), color); | ||
case 2: | ||
return new Rectangle(getRandomNumber(), getRandomNumber(), color); | ||
case 3: | ||
return new RightTriangle(getRandomNumber(), getRandomNumber(), color); | ||
default: | ||
return new Square(getRandomNumber(), color); | ||
} | ||
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(DEFAULT_RADIUS, DEFAULT_COLOR); | ||
} | ||
|
||
private int getRandomNumber() { | ||
return random.nextInt(MAX_LENGTH - 1) + 1; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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 core.basesyntax; | ||
|
||
public class IsoscelesTrapezoid extends Figure { | ||
private final int height; | ||
private final int firstBase; | ||
private final int secondBase; | ||
|
||
public IsoscelesTrapezoid(int height, int firstBase, int secondBase, String color) { | ||
super(color); | ||
this.height = height; | ||
this.firstBase = firstBase; | ||
this.secondBase = secondBase; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return (double) ((firstBase + secondBase) * height) / 2; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: isosceles trapezoid, area: " | ||
+ getArea() | ||
+ ", height: " + height | ||
+ ", first Base: " + firstBase | ||
+ ", secondBase: " | ||
+ secondBase | ||
+ ", color: " + color); | ||
} | ||
} |
This file contains 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,26 @@ | ||
package core.basesyntax; | ||
|
||
public class Rectangle extends Figure { | ||
private final int firstSide; | ||
private final int secondSide; | ||
|
||
public Rectangle(int firstSide, int secondSide, String color) { | ||
super(color); | ||
this.firstSide = firstSide; | ||
this.secondSide = secondSide; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return firstSide * secondSide; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: rectangle, area: " + getArea() | ||
+ ", firstSide: " | ||
+ firstSide + ", secondSide: " | ||
+ secondSide + ", color: " | ||
+ color); | ||
} | ||
} |
This file contains 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,28 @@ | ||
package core.basesyntax; | ||
|
||
public class RightTriangle extends Figure { | ||
private final int firstLeg; | ||
private final int secondLeg; | ||
|
||
public RightTriangle(int firstLeg, int secondLeg, String color) { | ||
super(color); | ||
this.firstLeg = firstLeg; | ||
this.secondLeg = secondLeg; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: right triangle, area: " | ||
+ getArea() | ||
+ ", first leg: " | ||
+ firstLeg + ", second leg:" | ||
+ secondLeg | ||
+ ", color: " | ||
+ color); | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return (double) firstLeg * secondLeg / 2; | ||
} | ||
} |
This file contains 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,24 @@ | ||
package core.basesyntax; | ||
|
||
public class Square extends Figure { | ||
private final int side; | ||
|
||
public Square(int side, String color) { | ||
super(color); | ||
this.side = side; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: square, area: " | ||
+ getArea() | ||
+ ", side: " | ||
+ side + ", color: " | ||
+ color); | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return side * side; | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
public class StructureTest { | ||
private static final List<String> figureClassNames = List | ||
.of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); | ||
.of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); | ||
private static List<Class> allClasses = new ArrayList<>(); | ||
|
||
@BeforeClass | ||
|
@@ -25,8 +25,8 @@ public static void init() { | |
allClasses = getClasses("core.basesyntax"); | ||
if (allClasses.size() == 0) { | ||
Assert.fail("You should not rename base core.basesyntax package " | ||
+ "and path to project and project name should not contain spaces " | ||
+ "or words in cyrillic"); | ||
+ "and path to project and project name should not contain spaces " | ||
+ "or words in cyrillic"); | ||
Comment on lines
+28
to
+29
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. I think you should only provide a solution and not change tests. |
||
} | ||
} catch (Exception e) { | ||
throw new RuntimeException("Could not load classes ", e); | ||
|
@@ -152,4 +152,4 @@ private static List<Class> findClasses(File directory, String packageName) | |
} | ||
return classes; | ||
} | ||
} | ||
} | ||
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. The same as above. |
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.
I think you should only provide a solution and not change tests.