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

created figures and interfaces with calculation and drawing methods #1326

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Tarask2
Copy link

@Tarask2 Tarask2 commented Oct 14, 2023

No description provided.

private final String[] colors = {"red", "green", "blue", "yellow", "purple", "orange", "pink"};

public String getRandomColor() {
Random random = new Random();

Choose a reason for hiding this comment

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

consider making class-level field

@@ -0,0 +1,5 @@
package core.basesyntax;

interface DrawFigure {

Choose a reason for hiding this comment

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

No need to tight interface name for figure only

Suggested change
interface DrawFigure {
interface Drawable {

Random random = new Random();
ColorSupplier colorSupplier = new ColorSupplier();

int figureType = random.nextInt(5);

Choose a reason for hiding this comment

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

avoid using magic numbers

consider making it constant


public class FigureSupplier {
public Figure getRandomFigure() {
Random random = new Random();

Choose a reason for hiding this comment

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

consider making class-level field

@Tarask2
Copy link
Author

Tarask2 commented Oct 22, 2023

Correct Task !!!
Pleas check !

public Figure getRandomFigure() {
Random random = new Random();
ColorSupplier colorSupplier = new ColorSupplier();

Choose a reason for hiding this comment

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

can be class-level private final variable

@@ -3,11 +3,12 @@
import java.util.Random;

public class FigureSupplier {
private Random random = new Random();

Choose a reason for hiding this comment

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

could be final

@@ -29,7 +30,7 @@ public Figure getRandomFigure() {
int topBase = random.nextInt() * 10;
int bottomBase = random.nextInt() * 10;
int heightTrapezoid = random.nextInt() * 10;
return new IsoscelesTrapezoid(color,topBase, bottomBase, heightTrapezoid);
return new IsoscelesTrapezoid(color, topBase, bottomBase, heightTrapezoid);

default:
return null;

Choose a reason for hiding this comment

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

you can return default figure instead of null
image

@@ -3,10 +3,10 @@
import java.util.Random;

public class ColorSupplier {
private Random random = new Random();
private final String[] colors = {"red", "green", "blue", "yellow", "purple", "orange", "pink"};

Choose a reason for hiding this comment

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

could be private static final

@@ -3,10 +3,10 @@
import java.util.Random;

public class ColorSupplier {
private Random random = new Random();

Choose a reason for hiding this comment

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

could be private final

@Tarask2 Tarask2 requested review from kerrrusha and sokimaaa October 30, 2023 04:57
Copy link

@Rommelua Rommelua left a comment

Choose a reason for hiding this comment

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

Before you create PR with your homework, you need to go through the checklist under the task and correct all the points described there. The mentor will not check the work until the checklist points are corrected

Comment on lines 3 to 5
interface AreaCalculator {

double calculateArea();

Choose a reason for hiding this comment

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

image

Comment on lines 5 to 6
class ColorSupplier {

Choose a reason for hiding this comment

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

image

Comment on lines 7 to 8
private static final String[] colors = {"red", "green", "blue", "yellow", "purple",
"orange", "pink"};

Choose a reason for hiding this comment

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

Let's remove this array and create enum Color (as a separate class)


public Figure getRandomFigure() {

final int figureType = random.nextInt(5);

Choose a reason for hiding this comment

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

image

@Tarask2 Tarask2 requested a review from Rommelua November 6, 2023 20:51
package core.basesyntax;

enum Colors {
RED, GREEN, WHITE, BLACK, BLUE;

Choose a reason for hiding this comment

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

Better write in stack instead line

Comment on lines +15 to +31
case 0:
return new Square(color, sideOrRadius);
case 1:
return new Circle(color, sideOrRadius);
case 2:
double width = random.nextDouble() * 10;
double height = random.nextDouble() * 10;
return new Rectangle(color, (int) width, (int) height);
case 3:
double firstLeg = random.nextDouble() * 10;
double secondLeg = random.nextDouble() * 10;
return new RightTriangle(color, (int) secondLeg, (int) firstLeg);
case 4:
int topBase = random.nextInt() * 10;
int bottomBase = random.nextInt() * 10;
int heightTrapezoid = random.nextInt() * 10;
return new IsoscelesTrapezoid(color, topBase, bottomBase, heightTrapezoid);

Choose a reason for hiding this comment

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

For every case you can create own method and you have a lot of duplicate code with your random values

}

public Figure getDefaultFigure() {
return new Circle("white", 10);

Choose a reason for hiding this comment

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

Use constant for parameters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants