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
Done 02-05/10/23 #1310
Open
leonidbondarenko69
wants to merge
1
commit into
mate-academy:master
Choose a base branch
from
leonidbondarenko69:Geometric_figures
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
Done 02-05/10/23 #1310
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 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,21 @@ | ||
package core.basesyntax; | ||
|
||
public class Circle extends Figure { | ||
private double radius; | ||
|
||
public Circle(String color, double radius) { | ||
super(color); | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public void calculateSquare() { | ||
System.out.println("Square circle = " + Math.PI * radius * radius); | ||
} | ||
|
||
@Override | ||
String getInfo() { | ||
return "Figure: Circle, area: " + Math.PI * radius * radius | ||
+ " sq.units, radius: " + radius + " units, color: " + getColor(); | ||
} | ||
} |
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,10 @@ | ||
package core.basesyntax; | ||
|
||
public enum Color { | ||
WHITE, | ||
BLUE, | ||
BLACK, | ||
RED, | ||
GREEN, | ||
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,12 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
private Random random = new Random(); | ||
|
||
public String getRandomColor() { | ||
int index = random.nextInt(Color.values().length); | ||
return Color.values()[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,15 @@ | ||
package core.basesyntax; | ||
|
||
public abstract class Figure implements SquareOfFigures { | ||
private String color; | ||
|
||
public Figure(String color) { | ||
this.color = color; | ||
} | ||
|
||
public String getColor() { | ||
return color; | ||
} | ||
|
||
abstract String getInfo(); | ||
} |
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,35 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class FigureSupplier { | ||
private static final int MAX_FIGURE = 6; | ||
private Random random = new Random(); | ||
private ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
||
public Figure getRandomFigure() { | ||
int randomNumberOfFigure = random.nextInt(MAX_FIGURE); | ||
switch (randomNumberOfFigure) { | ||
case 1: | ||
return new Circle(colorSupplier.getRandomColor(), random.nextInt(10)); | ||
case 2: | ||
return new IsoscelesTrapezoid(random.nextInt(10), | ||
random.nextInt(10), random.nextInt(10), | ||
colorSupplier.getRandomColor()); | ||
case 3: | ||
return new Rectangle(colorSupplier.getRandomColor(), | ||
random.nextInt(10), random.nextInt(10)); | ||
case 4: | ||
return new RightTriangle(colorSupplier.getRandomColor(), | ||
random.nextInt(10), random.nextInt(10)); | ||
case 5: | ||
return new Square(colorSupplier.getRandomColor(), random.nextInt(10)); | ||
default: | ||
return getDefaultFigure(); | ||
} | ||
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(Color.WHITE.name(), 10); | ||
} | ||
} |
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,27 @@ | ||
package core.basesyntax; | ||
|
||
public class IsoscelesTrapezoid extends Figure { | ||
private double sideOne; | ||
private double sideTwo; | ||
private double height; | ||
|
||
public IsoscelesTrapezoid(double sideOne, double sideTwo, double height, String color) { | ||
super(color); | ||
this.sideOne = sideOne; | ||
this.sideTwo = sideTwo; | ||
this.height = height; | ||
} | ||
|
||
@Override | ||
public void calculateSquare() { | ||
System.out.println("Square Of IsoscelesTrapezoid = " + (sideOne + sideTwo) / 2 * height); | ||
|
||
} | ||
|
||
@Override | ||
String getInfo() { | ||
return "Figure: IsoscelesTrapezoid, area: " + (sideOne + sideTwo) / 2 * height | ||
+ " sq.units, " + "sideOne " + sideOne + " units, " + "sideTwo " | ||
+ sideTwo + " units, " + "height " + height + ", color: " + getColor(); | ||
} | ||
} |
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,16 @@ | ||
package core.basesyntax; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
FigureSupplier figureSupplier = new FigureSupplier(); | ||
Figure[] figures = new Figure[6]; | ||
for (int i = 0; i < figures.length; i++) { | ||
if (i < 3) { | ||
figures[i] = figureSupplier.getRandomFigure(); | ||
} else { | ||
figures[i] = figureSupplier.getDefaultFigure(); | ||
} | ||
System.out.println(figures[i].getInfo()); | ||
} | ||
} | ||
} |
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 Rectangle extends Figure { | ||
private double sideOne; | ||
private double sideTwo; | ||
|
||
public Rectangle(String color, double sideOne, double sideTwo) { | ||
super(color); | ||
this.sideOne = sideOne; | ||
this.sideTwo = sideTwo; | ||
} | ||
|
||
@Override | ||
public void calculateSquare() { | ||
System.out.println("Square of Rectangle = " + sideOne * sideTwo); | ||
} | ||
|
||
@Override | ||
String getInfo() { | ||
return "Figure: Rectangle, area: " + sideOne * sideTwo | ||
+ " sq.units, " + "sideOne " + sideOne + " units, " + "sideTwo " | ||
+ sideTwo + " units, " + "color: " + getColor(); | ||
} | ||
} |
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 RightTriangle extends Figure { | ||
private double sideOne; | ||
private double sideTwo; | ||
|
||
public RightTriangle(String color, double sideOne, double sideTwo) { | ||
super(color); | ||
this.sideOne = sideOne; | ||
this.sideTwo = sideTwo; | ||
} | ||
|
||
@Override | ||
public void calculateSquare() { | ||
System.out.println("Square of RightTriangle = " + (sideOne * sideTwo) / 2); | ||
} | ||
|
||
@Override | ||
String getInfo() { | ||
return "Figure: RightTriangle, area: " + (sideOne * sideTwo) / 2 | ||
+ " sq.units, " + "sideOne " + sideOne + " units, " + "sideTwo " | ||
+ sideTwo + " units, " + "color: " + getColor(); | ||
} | ||
} |
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,21 @@ | ||
package core.basesyntax; | ||
|
||
public class Square extends Figure { | ||
private double side; | ||
|
||
public Square(String color, double side) { | ||
super(color); | ||
this.side = side; | ||
} | ||
|
||
@Override | ||
public void calculateSquare() { | ||
System.out.println("Square of square = " + side * side); | ||
} | ||
|
||
@Override | ||
String getInfo() { | ||
return "Figure: Square, area: " + side | ||
+ " sq.units, " + "side " + side + " units, " + "color: " + getColor(); | ||
} | ||
} |
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 SquareOfFigures { | ||
void calculateSquare(); | ||
} |
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.
Please extract magic numbers to constants with proper naming