-
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
jv-oop-advanced homework #1297
base: master
Are you sure you want to change the base?
jv-oop-advanced homework #1297
Conversation
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.
Good job, but there are some changes should be done.
Also please check this article. It's better to use this method inside print
, instead String concatenation.
} | ||
} | ||
for (Figure figure : figures) { | ||
figure.getArea(); |
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.
Why did you make this call and then ignore result of it?
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.
get.Area is already implemented in a print method so it has no sense to call it 2 times, don't know why I did it)
|
||
@Override | ||
public double getArea() { | ||
return (side * height) / 2; |
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.
integer division in floating-point context .
Please pay attention to this article.
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.
Should I give height field a double value by default or should I cast it to double in a getArea method? Hope I changed it in a right way
|
||
@Override | ||
public double getArea() { | ||
return ((side + side) / 2) * height; |
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.
integer division in floating-point context .
Please pay attention to this article.
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(Color.WHITE, 10); |
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.
All magic numbers in your code should be constants.
Please see this article to learn about constant fields and their naming requirements.
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.
Didn't notice that, changed
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.
Good job, just minor updates are required.
@@ -0,0 +1,5 @@ | |||
package core.basesyntax; | |||
|
|||
public interface GetArea { |
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.
Think about this.
package core.basesyntax; | ||
|
||
public interface Print { | ||
void print(); |
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 figure should draw
instead of print
. In the task: To 'draw' means to print
.
Lets rename it to Drawable
with void draw()
.
int index = random.nextInt(Color.values().length); | ||
return Color.values()[index]; |
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 can make Color.values()
as separate class field.
double sideD = side; | ||
double heightD = height; |
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.
Remove it.
package core.basesyntax; | ||
|
||
public class Circle extends Figure { | ||
private Color color; |
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.
You already have Color color
field in Figure
class.
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.
It has no sence, cuz it has to be inharited from Figure. Changed that everywhere
double sideD = side; | ||
double heightD = height; |
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.
Remove it.
private Random random = new Random(); | ||
|
||
public Color getRandomColor() { | ||
int index = random.nextInt(Color.values().length); |
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.
Minor: you already have the field which holds colors, you can reuse it here
static final int FIGURE_AMOUNT = 5; | ||
static final int FIGURE_PARAMETERS_MAX = 20; | ||
static final Color DEFAULT_COLOR = Color.WHITE; | ||
static final int DEFAULT_RADIUS = 10; |
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.
Don't forget to make these fields private
case 0: { | ||
return new Circle(colorSupplier.getRandomColor(), randomFigureParameter); | ||
} | ||
case 1: { | ||
return new Square(colorSupplier.getRandomColor(), randomFigureParameter); | ||
} | ||
case 2: { | ||
return new Rectangle(colorSupplier.getRandomColor(), | ||
randomFigureParameter, randomFigureParameter); | ||
} | ||
case 3: { | ||
return new RightTriangle(colorSupplier.getRandomColor(), | ||
randomFigureParameter, randomFigureParameter); | ||
} | ||
default: { | ||
return new IsoscelesTrapezoid(colorSupplier.getRandomColor(), | ||
randomFigureParameter, randomFigureParameter); |
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.
since each figure needs a color you can extract colorSupplier.getRandomColor() to a separate variable and reuse
case 0: { | ||
return new Circle(colorSupplier.getRandomColor(), randomFigureParameter); | ||
} | ||
case 1: { | ||
return new Square(colorSupplier.getRandomColor(), randomFigureParameter); | ||
} | ||
case 2: { | ||
return new Rectangle(colorSupplier.getRandomColor(), | ||
randomFigureParameter, randomFigureParameter); | ||
} | ||
case 3: { | ||
return new RightTriangle(colorSupplier.getRandomColor(), | ||
randomFigureParameter, randomFigureParameter); | ||
} | ||
default: { | ||
return new IsoscelesTrapezoid(colorSupplier.getRandomColor(), | ||
randomFigureParameter, randomFigureParameter); |
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.
Your method is not fully random. For example, your Rectangle will always be a square since you pass the same randomFigureParameter there. So sizes of rectangle will always be equal. Please refactor this part
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.
Well done :)
No description provided.