-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
doneHomework #1248
base: master
Are you sure you want to change the base?
doneHomework #1248
Changes from 1 commit
e3df59c
1bc6c25
3ec309d
9c5273f
8c85d7e
42acf42
a4dac18
56f85c7
8607865
67300ae
728c43f
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 |
---|---|---|
|
@@ -2,6 +2,12 @@ | |
|
||
public class Application { | ||
public static void main(String[] args) { | ||
// create three balls using class Lottery and print information about them in console | ||
Lottery lottery1 = new Lottery(); | ||
Lottery lottery2 = new Lottery(); | ||
Lottery lottery3 = new Lottery(); | ||
|
||
System.out.println(lottery1.getRandomBall()); | ||
System.out.println(lottery2.getRandomBall()); | ||
System.out.println(lottery3.getRandomBall()); | ||
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 for loop for creating several objects of the same class |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
|
||
private 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. |
||
private int number; | ||
|
||
public Ball(String color, int number) { | ||
this.color = color; | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{Color: " + color + ", number: " + number + "}"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
|
||
public String getRandomColor() { | ||
return null; | ||
int index = new Random().nextInt(Colors.values().length); | ||
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. make random the class level var |
||
return Colors.values()[index].toString(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,12 @@ | ||||||
package core.basesyntax; | ||||||
|
||||||
public enum Colors { | ||||||
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. dont use plural form for enums
Suggested change
|
||||||
RED, | ||||||
GREEN, | ||||||
WHITE, | ||||||
BLACK, | ||||||
PINK, | ||||||
GREY, | ||||||
BLUE, | ||||||
PURPLE | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
|
||
public Ball getRandomBall() { | ||
int randomNumber = new Random().nextInt(100); | ||
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. 100 is a maggic number, |
||
return new Ball(new ColorSupplier().getRandomColor(), 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. make |
||
} | ||
} |
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.
Do we need 3 markets to buy 3 milk bottles?