-
Notifications
You must be signed in to change notification settings - Fork 0
added students solution to review #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
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,35 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public class Ball { | ||
| String ballColor; | ||
| int ballNumber; | ||
|
Comment on lines
+4
to
+5
Owner
Author
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 the private access modifier for internal variables |
||
|
|
||
| public Ball() { | ||
| } | ||
|
|
||
| public Ball(String color, int number) { | ||
| this.ballColor = color; | ||
| this.ballNumber = number; | ||
| } | ||
|
|
||
| public String getBallColor() { | ||
| return this.ballColor; | ||
| } | ||
|
|
||
| public void setBallColor(String ballColor) { | ||
| this.ballColor = ballColor; | ||
| } | ||
|
|
||
| public int getBallNumber() { | ||
| return this.ballNumber; | ||
| } | ||
|
|
||
| public void setBallNumber(int ballNumber) { | ||
| this.ballNumber = ballNumber; | ||
| } | ||
|
|
||
|
Owner
Author
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. add annotation @Override |
||
| public String toString() { | ||
| String ball = "ball"; | ||
|
Owner
Author
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. avoid variables you don't use |
||
| return "Ball with number: " + ballNumber + " and color: " + ballColor; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class ColorSupplier { | ||
| public String getRandomColor() { | ||
| return null; | ||
|
|
||
|
|
||
| public static String getRandomColor() { | ||
|
Owner
Author
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. Static methods are in general a bad practice. Let’s better create an instance of a class which method you want to call |
||
| int index = new Random().nextInt(Colors.values().length); | ||
| return Colors.values()[index].toString(); | ||
|
Owner
Author
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. It’s better to use standard method of enum name() that will be returning always String representation of concrete enum constant. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public enum Colors { | ||
| black, | ||
| white, | ||
| red, | ||
| blue | ||
|
Comment on lines
+4
to
+7
Owner
Author
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. As a rule, constants and Enums have names in upper case. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Lottery extends ColorSupplier { | ||
|
Owner
Author
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 is no benefit from this "extends" |
||
| public Ball getRandomBall() { | ||
|
|
||
| Ball ball = new Ball(); | ||
|
Owner
Author
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 can add parameters to the constructor and avoid calling setters
Owner
Author
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. Don’t create temporary variables if you can directly return value from the method |
||
|
|
||
| ball.setBallColor(ColorSupplier.getRandomColor()); | ||
|
|
||
| ball.setBallNumber(new Random().nextInt(100)); | ||
|
Owner
Author
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. All magic numbers in your code should be constants. |
||
|
|
||
|
Comment on lines
+7
to
+13
Owner
Author
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. Please don’t add redundant empty lines to your code. |
||
| return ball; | ||
| } | ||
| } | ||
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.
Use for loop for creating several objects and output of the same data