Skip to content
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 1.0 #1769

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
<linkXRef>false</linkXRef>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/AbstractFigure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

public abstract class AbstractFigure implements Figure,Print {
private String color;

public AbstractFigure(String color) {
this.color = color;
}

public String getColor() {
return color;
}
}
19 changes: 19 additions & 0 deletions src/main/java/core/basesyntax/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package core.basesyntax;

public class Circle extends AbstractFigure {
private double radius;

public Circle(String color, double radius) {
super(color);
this.radius = radius;
}

public double getArea() {
return Math.PI * radius * radius;
}

@Override
public String describe() {
return "Circle " + getColor() + " radius: " + radius + " area: " + getArea();
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core.basesyntax;

import java.util.Random;

public class ColorSupplier {
public String getRandomColor() {
String[] colors = {"Red","Green","Blue","Yellow","Black","Purple"};
Random random = new Random();
String randomColor = colors[random.nextInt(colors.length)];
return randomColor;
}
}
5 changes: 5 additions & 0 deletions src/main/java/core/basesyntax/Figure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package core.basesyntax;

public interface Figure {
double getArea();
}
39 changes: 39 additions & 0 deletions src/main/java/core/basesyntax/FigureSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package core.basesyntax;

import java.util.Random;

public class FigureSupplier {
public AbstractFigure getRandomFigure() {
Random random = new Random();
ColorSupplier colorSupplier = new ColorSupplier();
String color = colorSupplier.getRandomColor();
int figureType = random.nextInt(5);
switch (figureType) {
case 0: //Circle
double radius = 1 + random.nextInt(10);
return new Circle(color,radius);
case 1: //RightTriangle
double base = 1 + random.nextInt(10);
double heigth = 1 + random.nextInt(10);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

return new RightTriangle(color,base,heigth);
case 2: //Square
double side = 1 + random.nextInt(10);
return new Square(color,side);
case 3: //IsoscelesTrapezoid
double side1 = 1 + random.nextInt(10);
double side2 = 1 + random.nextInt(10);
heigth = 1 + random.nextInt(10);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

return new IsoscelesTrapezoid(color,side1,side2,heigth);
case 4: //Rectangle
double length = 1 + random.nextInt(10);
double width = 1 + random.nextInt(10);
return new Rectangle(color,length,width);
Comment on lines +13 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using constants for the magic numbers (e.g., 1 and 10) to improve code readability and maintainability.

default:
throw new IllegalStateException("Unexpected value: " + figureType);
}
}

public Figure getDefaultFigure() {
return new Circle("white",10);
}
}
8 changes: 0 additions & 8 deletions src/main/java/core/basesyntax/HelloWorld.java

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/java/core/basesyntax/IsoscelesTrapezoid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package core.basesyntax;

public class IsoscelesTrapezoid extends AbstractFigure {
private double base1;
private double base2;
private double heigth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.


public IsoscelesTrapezoid(String color, double base1, double base2, double height) {
super(color);
this.base1 = base1;
this.base2 = base2;
this.heigth = height;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

}

public double getArea() {
return 0.5 * (base1 + base2) * heigth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

}

@Override
public String describe() {
return "IsoscelesTrapezoid " + getColor() + " base1: " + base1 + " base2: " + base2
+ " height: " + heigth + " area: " + getArea();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

}
}
16 changes: 16 additions & 0 deletions src/main/java/core/basesyntax/MainApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package core.basesyntax;

public class MainApp {
public static void main(String[] args) {
AbstractFigure[] figures = new AbstractFigure[6];
FigureSupplier figureSupplier = new FigureSupplier();
for (int i = 0; i < 3;i++) {
figures[i] = figureSupplier.getRandomFigure();
System.out.println(figures[i].describe());
}
for (int i = 3; i < 6;i++) {
figures[i] = (AbstractFigure) figureSupplier.getDefaultFigure();
System.out.println(figures[i].describe());
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/core/basesyntax/Print.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package core.basesyntax;

public interface Print extends Figure {
String describe();
}
22 changes: 22 additions & 0 deletions src/main/java/core/basesyntax/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package core.basesyntax;

public class Rectangle extends AbstractFigure {
private double length;
private double width;

public Rectangle(String color, double length, double width) {
super(color);
this.length = length;
this.width = width;
}

public double getArea() {
return length * width;
}

@Override
public String describe() {
return "Rectangle " + getColor() + " length: " + length + " width: "
+ width + " area: " + getArea();
}
}
22 changes: 22 additions & 0 deletions src/main/java/core/basesyntax/RightTriangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package core.basesyntax;

public class RightTriangle extends AbstractFigure {
private double base;
private double heigth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.


public RightTriangle(String color,double base, double heigth) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

super(color);
this.base = base;
this.heigth = heigth;
Comment on lines +7 to +10

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

}

public double getArea() {
return 0.5 * base * heigth;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

}

@Override
public String describe() {
return "RightTriange " + getColor() + " base: " + base + " heigth: "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

+ heigth + " area: " + getArea();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable heigth is misspelled. It should be height to maintain code clarity and prevent potential bugs.

}
}
19 changes: 19 additions & 0 deletions src/main/java/core/basesyntax/Square.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package core.basesyntax;

public class Square extends AbstractFigure {
private double side;

public Square(String color, double side) {
super(color);
this.side = side;
}

public double getArea() {
return side * side;
}

@Override
public String describe() {
return "Square " + getColor() + " side: " + side + " area: " + getArea();
}
}
Loading