-
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
Added necessary Classes/Test passed #1508
base: master
Are you sure you want to change the base?
Changes from 5 commits
33c5e7a
12ba226
00b27bf
bbea4bc
b199840
43bc474
6825857
c5b8314
7442331
438ef1d
457884c
b3e928b
fabe0aa
999412e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package core.basesyntax; | ||
|
||
public class Circle extends Figure { | ||
private final double radius; | ||
|
||
public Circle(Color color, double radius) { | ||
super(String.valueOf(color)); | ||
this.radius = radius; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return Math.PI * radius * radius; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: Circle, area : " + getArea() | ||
+ " sq. units, radius: " + radius + " units, color: " + color); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package core.basesyntax; | ||
|
||
public enum Color { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a method to get a random color from the enum. This would be useful for the ColorSupplier class to generate random colors. |
||
RED, | ||
ORANGE, | ||
PINK, | ||
YELLOW, | ||
WHITE, | ||
BLACK, | ||
LIME, | ||
CYAN | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
|
||
private static final Random RANDOM = new Random(); | ||
|
||
public static Color getRandomColor() { | ||
Color[] colors = Color.values(); | ||
int randomIndex = RANDOM.nextInt(colors.length); | ||
return colors[randomIndex]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package core.basesyntax; | ||
|
||
public interface Colorful { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This interface is unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not fixed |
||
String getColor(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package core.basesyntax; | ||
|
||
public interface Drawable { | ||
void draw(); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's refactor this class to this: public abstract class Figure implements FigureInfo, AreaCalculator {
private Color color;
public Figure(Color color) {
this.color = color;
}
public Color getColor() {
return color;
}
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package core.basesyntax; | ||
|
||
public abstract class Figure implements Drawable, Colorful { | ||
protected String color; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've created an enum for colors - why you didn't use it here?? |
||
|
||
public Figure() { | ||
this.color = "white"; | ||
} | ||
|
||
public interface Drawable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you put this interface here? You've already created it in separate file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
void draw(); | ||
} | ||
|
||
public interface Colorful { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you put this interface here? You've already created it in separate file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
String getColor(); | ||
} | ||
|
||
public Figure(String color) { | ||
this.color = color; | ||
} | ||
|
||
public abstract double getArea(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be provided by interface implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed for the second time |
||
|
||
public abstract void draw(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is unnecessary if you If you're implementing an abstract class - interface will provide it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
|
||
public String getColor() { | ||
return color; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package core.basesyntax; | ||
|
||
public class FigureSupplier { | ||
|
||
public static Figure getRandomFigure() { | ||
int randomNumber = (int) (Math.random() * 5); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
|
||
switch (randomNumber) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameters for each figure should be random as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed for the second time |
||
case 0: | ||
return new Square(ColorSupplier.getRandomColor(), 5); | ||
case 1: | ||
return new Rectangle(ColorSupplier.getRandomColor(), 7, 5); | ||
case 2: | ||
return new RightTriangle(ColorSupplier.getRandomColor(), 3, 4); | ||
case 3: | ||
return new Circle(ColorSupplier.getRandomColor(), 10); | ||
case 4: | ||
return new IsoscelesTrapezoid(ColorSupplier.getRandomColor(), 6, 10, 4); | ||
default: | ||
return new Circle(Color.WHITE, 10); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
*/ | ||
public class HelloWorld { | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package core.basesyntax; | ||
|
||
public class IsoscelesTrapezoid extends Figure { | ||
private final double firstLeg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These names tell nothing about the sides they are referring to. Use:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
private final double secondLeg; | ||
private final double thirdLeg; | ||
|
||
public IsoscelesTrapezoid(Color color, double firstLeg, double secondLeg, double thirdLeg) { | ||
super(String.valueOf(color)); | ||
this.firstLeg = firstLeg; | ||
this.secondLeg = secondLeg; | ||
this.thirdLeg = thirdLeg; | ||
} | ||
|
||
@Override | ||
|
||
public double getArea() { | ||
return ((firstLeg * secondLeg) * thirdLeg) / 2; | ||
} | ||
|
||
@Override | ||
|
||
public void draw() { | ||
System.out.println("Figure: RightTriangle, area : " + getArea() + " sq. units, firstLeg: " | ||
+ firstLeg + " secondLeg: " | ||
+ secondLeg + " thirdLeg: " + thirdLeg + " units, color: " + color); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package core.basesyntax; | ||
|
||
public class Rectangle extends Figure { | ||
private final double firstLeg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here - width and height are more appropriate. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
private final double secondLeg; | ||
|
||
public Rectangle(Color color, double firstLeg, double secondLeg) { | ||
super(String.valueOf(color)); | ||
this.firstLeg = firstLeg; | ||
this.secondLeg = secondLeg; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return firstLeg * secondLeg; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: RightTriangle, area : " + getArea() | ||
+ " sq. units, firstLeg: " + firstLeg | ||
+ " secondLeg: " + secondLeg + " units, color: " + color); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package core.basesyntax; | ||
|
||
public class RightTriangle extends Figure { | ||
|
||
private final double firstLeg; | ||
private final double secondLeg; | ||
|
||
public RightTriangle(Color color, double firstLeg, double secondLeg) { | ||
super(String.valueOf(color)); | ||
this.firstLeg = firstLeg; | ||
this.secondLeg = secondLeg; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return (firstLeg * secondLeg) / 2; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: RightTriangle, area : " + getArea() | ||
+ " sq. units, firstLeg: " + firstLeg | ||
+ " secondLeg: " + secondLeg + " units, color: " + color); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package core.basesyntax; | ||
|
||
public class Square extends Figure { | ||
private final double firstLeg; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not fixed |
||
|
||
public Square(Color color, double firstLeg) { | ||
super(String.valueOf(color)); | ||
this.firstLeg = firstLeg; | ||
} | ||
|
||
@Override | ||
public double getArea() { | ||
return firstLeg * firstLeg; | ||
} | ||
|
||
@Override | ||
public void draw() { | ||
System.out.println("Figure: RightTriangle, area : " + getArea() + " sq. units, firstLeg: " | ||
+ firstLeg + " units, 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.
Why did you keep a String type in base class, when you're using a Color instance everywhere else? Please fix this in base class.