generated from mate-academy/jv-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added interface CalculateArea.java, class Circle.java, class ColorSup…
…plier.java, interface Colors.java, interface Drawable.java, class Figure.java, class FigureSupplier.java, interface Figures.java, class IsoscelesTrapezoid.java, class Rectangle.java, class RightTriangle.java, class Square.java; Changed HelloWorld.java
- Loading branch information
1 parent
3b03b22
commit 34e82cb
Showing
13 changed files
with
225 additions
and
0 deletions.
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,5 @@ | ||
package core.basesyntax; | ||
|
||
public interface CalculateArea { | ||
double getS(); | ||
} |
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,20 @@ | ||
package core.basesyntax; | ||
|
||
public class Circle extends Figure { | ||
private double radius; | ||
|
||
public Circle(String color, double radius) { | ||
super(color); | ||
this.radius = radius; | ||
} | ||
|
||
public double getS() { | ||
return 3.14 * Math.pow(this.radius, 2); | ||
} | ||
|
||
@Override | ||
public void drawFigure() { | ||
System.out.println("Коло { радіус = " + this.radius + ", площа = " | ||
+ getS() + ", колір - " + 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,11 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public String getRandomColor() { | ||
int index = new Random().nextInt(Colors.values().length); | ||
Colors color = Colors.values()[index]; | ||
return color.toString(); | ||
} | ||
} |
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,11 @@ | ||
package core.basesyntax; | ||
|
||
public enum Colors { | ||
RED, | ||
BLUE, | ||
GREEN, | ||
BLACK, | ||
ORANGE, | ||
YELLOW, | ||
WHITE | ||
} |
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 drawFigure(); | ||
} |
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,17 @@ | ||
package core.basesyntax; | ||
|
||
public abstract class Figure implements Drawable, CalculateArea { | ||
private String color; | ||
|
||
public Figure(String color) { | ||
this.color = color; | ||
} | ||
|
||
public abstract double getS(); | ||
|
||
public abstract void drawFigure(); | ||
|
||
public String getColor() { | ||
return this.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,36 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class FigureSupplier { | ||
public Figure getRandomFigure() { | ||
ColorSupplier colorSupplier = new ColorSupplier(); | ||
Random random = new Random(); | ||
int index = random.nextInt(Figures.values().length); | ||
Figures figure = Figures.values()[index]; | ||
|
||
switch (figure.toString()) { | ||
case "SQUARE": | ||
return new Square(colorSupplier.getRandomColor(), random.nextDouble() * 100); | ||
case "RECTANGLE": | ||
return new Rectangle(colorSupplier.getRandomColor(), | ||
random.nextDouble() * 100, random.nextDouble() * 100); | ||
case "RIGHT_TRIANGLE": | ||
return new RightTriangle(colorSupplier.getRandomColor(), random.nextDouble() * 100, | ||
random.nextDouble() * 100, random.nextDouble() * 100); | ||
case "CIRCLE": | ||
return new Circle(colorSupplier.getRandomColor(), random.nextDouble() * 100); | ||
case "ISOSCELES_TRAPEZOID": | ||
return new IsoscelesTrapezoid(colorSupplier.getRandomColor(), | ||
random.nextDouble() * 100, | ||
random.nextDouble() * 100, | ||
random.nextDouble() * 100); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(Colors.WHITE.toString(), 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,9 @@ | ||
package core.basesyntax; | ||
|
||
public enum Figures { | ||
SQUARE, | ||
RECTANGLE, | ||
RIGHT_TRIANGLE, | ||
CIRCLE, | ||
ISOSCELES_TRAPEZOID | ||
} |
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
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 IsoscelesTrapezoid extends Figure { | ||
private double base1; | ||
private double base2; | ||
private double height; | ||
|
||
public IsoscelesTrapezoid(String color, double base1, double base2, double height) { | ||
super(color); | ||
this.base1 = base1; | ||
this.base2 = base2; | ||
this.height = height; | ||
} | ||
|
||
public double getS() { | ||
return ((this.base1 + this.base2) / 2) * this.height; | ||
} | ||
|
||
@Override | ||
public void drawFigure() { | ||
System.out.println("Рівнобічна трапеція { основа1 = " + this.base1 | ||
+ ", основа2 = " + this.base2 | ||
+ ", висота = " + this.height + ", площа = " + getS() | ||
+ "колір - " + 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,23 @@ | ||
package core.basesyntax; | ||
|
||
public class Rectangle extends Figure { | ||
private double side1; | ||
private double side2; | ||
|
||
public Rectangle(String color, double side1, double side2) { | ||
super(color); | ||
this.side1 = side1; | ||
this.side2 = side2; | ||
} | ||
|
||
@Override | ||
public double getS() { | ||
return side1 * side2; | ||
} | ||
|
||
@Override | ||
public void drawFigure() { | ||
System.out.println("Прямокутник { сторона1 = " + this.side1 + ", сторона2 = " + this.side2 | ||
+ ", площа = " + getS() + ", колір - " + 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,26 @@ | ||
package core.basesyntax; | ||
|
||
public class RightTriangle extends Figure { | ||
private double leg1; | ||
private double leg2; | ||
private double hypotenusa; | ||
|
||
public RightTriangle(String color, double leg1, double leg2, double hypotenusa) { | ||
super(color); | ||
this.leg1 = leg1; | ||
this.leg2 = leg2; | ||
this.hypotenusa = hypotenusa; | ||
} | ||
|
||
public double getS() { | ||
return (this.leg1 * this.leg2) / 2; | ||
} | ||
|
||
@Override | ||
public void drawFigure() { | ||
System.out.println("Прямокутний трикутник { катет1 = " + this.leg1 + ", катет2 = " | ||
+ this.leg2 + ", гіпотенуза = " + this.hypotenusa | ||
+ ", площа = " + getS() | ||
+ ", колір - " + 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 double getS() { | ||
return Math.pow(this.side, 2); | ||
} | ||
|
||
@Override | ||
public void drawFigure() { | ||
System.out.println("Квадрат { сторона = " + this.side + ", площа = " | ||
+ getS() + ", колір - " + getColor() + " }"); | ||
} | ||
} |