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

Added necessary Classes/Test passed #1508

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
21 changes: 21 additions & 0 deletions src/main/java/core/basesyntax/Circle.java
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));

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.

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);
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/basesyntax/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core.basesyntax;

public enum Color {
Copy link

Choose a reason for hiding this comment

The 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
}
14 changes: 14 additions & 0 deletions src/main/java/core/basesyntax/ColorSupplier.java
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];
}
}
5 changes: 5 additions & 0 deletions src/main/java/core/basesyntax/Colorful.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package core.basesyntax;

public interface Colorful {

Choose a reason for hiding this comment

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

This interface is unnecessary.

Choose a reason for hiding this comment

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

not fixed

String getColor();
}
5 changes: 5 additions & 0 deletions src/main/java/core/basesyntax/Drawable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package core.basesyntax;

public interface Drawable {
void draw();
}
30 changes: 30 additions & 0 deletions src/main/java/core/basesyntax/Figure.java

Choose a reason for hiding this comment

The 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;

Choose a reason for hiding this comment

The 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 {

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

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

Not fixed

void draw();
}

public interface Colorful {

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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();

Choose a reason for hiding this comment

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

This should be provided by interface implementation.

Choose a reason for hiding this comment

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

Not fixed

Choose a reason for hiding this comment

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

Not fixed for the second time


public abstract void draw();

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

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

Not fixed


public String getColor() {
return color;
}
}

23 changes: 23 additions & 0 deletions src/main/java/core/basesyntax/FigureSupplier.java
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);

Choose a reason for hiding this comment

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

Use Random instance (constant), any limiters should be extracted as a constants.

Choose a reason for hiding this comment

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

Not fixed


switch (randomNumber) {

Choose a reason for hiding this comment

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

Parameters for each figure should be random as well.

Choose a reason for hiding this comment

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

Not fixed

Choose a reason for hiding this comment

The 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);
}
}
}
1 change: 1 addition & 0 deletions src/main/java/core/basesyntax/HelloWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
*/
public class HelloWorld {


Choose a reason for hiding this comment

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

Unnecessary change.

Choose a reason for hiding this comment

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

Not fixed

}
28 changes: 28 additions & 0 deletions src/main/java/core/basesyntax/IsoscelesTrapezoid.java
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;

Choose a reason for hiding this comment

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

These names tell nothing about the sides they are referring to. Use:

  • topSize
  • bottomSide
  • height

Choose a reason for hiding this comment

The 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);
}
}
24 changes: 24 additions & 0 deletions src/main/java/core/basesyntax/Rectangle.java
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;

Choose a reason for hiding this comment

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

Same here - width and height are more appropriate.

Choose a reason for hiding this comment

The 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);
}
}
26 changes: 26 additions & 0 deletions src/main/java/core/basesyntax/RightTriangle.java
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);
}
}

21 changes: 21 additions & 0 deletions src/main/java/core/basesyntax/Square.java
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;

Choose a reason for hiding this comment

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

side, there are no other legs except the first one.

Choose a reason for hiding this comment

The 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);
}
}
Loading