-
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
Add files via upload #1696
base: master
Are you sure you want to change the base?
Add files via upload #1696
Changes from 1 commit
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,12 @@ | ||
public class Ball { | ||
int number; | ||
Colors color; | ||
public Ball(int number, Colors color){ | ||
this.number = number; | ||
this.color = color; | ||
} | ||
|
||
public String toString(){ | ||
return "Ball" + "color" + number; | ||
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. The |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public Colors getRandomColor() { | ||
Random random = new Random(); | ||
Colors[] color = Colors.values(); | ||
int sum = random.nextInt(color.length); | ||
return color[sum]; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public enum Colors { | ||
Red, | ||
Green, | ||
Blue, | ||
Yellow, | ||
Orange, | ||
Purple, | ||
Black, | ||
White, | ||
Pink, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import java.util.Random; | ||
|
||
public class Lottery { | ||
public static Ball getRandomBall(){ | ||
Random random = new Random(); | ||
int numb = random.nextInt(100); | ||
ColorSupplier ColorsSupplier = new ColorSupplier(); | ||
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. The variable name 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. The variable name |
||
Colors color = ColorsSupplier.getRandomColor(); | ||
Ball Ball = new Ball(numb, 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. The variable name 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. The variable name |
||
return Ball; | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or | ||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter. | ||
public class Main { | ||
public static void main(String[] args) { | ||
Ball Ball1 = Lottery.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. The variable name |
||
Ball Ball2 = Lottery.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. The variable name |
||
Ball Ball3 = Lottery.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. The variable name 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. The variable names |
||
System.out.println(Ball1); | ||
System.out.println(Ball2); | ||
System.out.println(Ball3); | ||
} | ||
} |
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.
The
toString
method should return a string that includes the actual color of the ball. Replace'color'
withcolor
to use theColors
enum value, and consider adding a space or other separator between 'Ball', the color, and the number for better readability.