Skip to content

added students solution to review#1

Open
Ivan95kos wants to merge 1 commit into
mainfrom
add-solution-to-review
Open

added students solution to review#1
Ivan95kos wants to merge 1 commit into
mainfrom
add-solution-to-review

Conversation

@Ivan95kos
Copy link
Copy Markdown
Owner

No description provided.

Comment on lines +5 to +10
Lottery ball1 = new Lottery();
System.out.println(ball1.getRandomBall().toString());
Lottery ball2 = new Lottery();
System.out.println(ball2.getRandomBall().toString());
Lottery ball3 = new Lottery();
System.out.println(ball3.getRandomBall().toString());
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Use for loop for creating several objects and output of the same data

}

public String toString() {
String ball = "ball";
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

avoid variables you don't use


public static String getRandomColor() {
int index = new Random().nextInt(Colors.values().length);
return Colors.values()[index].toString();
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

It’s better to use standard method of enum name() that will be returning always String representation of concrete enum constant.

return null;


public static String getRandomColor() {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Static methods are in general a bad practice. Let’s better create an instance of a class which method you want to call

Comment on lines +4 to +5
String ballColor;
int ballNumber;
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

use the private access modifier for internal variables

Comment on lines +7 to +13

Ball ball = new Ball();

ball.setBallColor(ColorSupplier.getRandomColor());

ball.setBallNumber(new Random().nextInt(100));

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Please don’t add redundant empty lines to your code.

public class Lottery extends ColorSupplier {
public Ball getRandomBall() {

Ball ball = new Ball();
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

you can add parameters to the constructor and avoid calling setters

public class Lottery extends ColorSupplier {
public Ball getRandomBall() {

Ball ball = new Ball();
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Don’t create temporary variables if you can directly return value from the method


import java.util.Random;

public class Lottery extends ColorSupplier {
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

there is no benefit from this "extends"


ball.setBallColor(ColorSupplier.getRandomColor());

ball.setBallNumber(new Random().nextInt(100));
Copy link
Copy Markdown
Owner Author

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.

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.

2 participants