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

Add files via upload #1696

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions Ball.java
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;

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' with color to use the Colors enum value, and consider adding a space or other separator between 'Ball', the color, and the number for better readability.

Choose a reason for hiding this comment

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

The toString method does not correctly concatenate the color and number fields. It currently returns the string 'Ballcolor' followed by the number. You should use this.color and this.number to properly include the object's fields in the returned string. Consider using: return "Ball: " + this.color + " " + this.number;

}
}
11 changes: 11 additions & 0 deletions ColorSupplier.java
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];
}
}

11 changes: 11 additions & 0 deletions Colors.java
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,
}
14 changes: 14 additions & 0 deletions Lottery.java
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();

Choose a reason for hiding this comment

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

The variable name ColorsSupplier should follow camelCase naming conventions. Consider renaming it to colorSupplier.

Choose a reason for hiding this comment

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

The variable name ColorsSupplier should follow camelCase naming conventions. Consider renaming it to colorSupplier for consistency with Java naming standards.

Colors color = ColorsSupplier.getRandomColor();
Ball Ball = new Ball(numb, color);

Choose a reason for hiding this comment

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

The variable name Ball should follow camelCase naming conventions. Consider renaming it to ball.

Choose a reason for hiding this comment

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

The variable name Ball should start with a lowercase letter to follow Java naming conventions. Consider renaming it to ball.

return Ball;
}

}

12 changes: 12 additions & 0 deletions Main.java
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();

Choose a reason for hiding this comment

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

The variable name Ball1 should follow camelCase naming conventions. Consider renaming it to ball1.

Ball Ball2 = Lottery.getRandomBall();

Choose a reason for hiding this comment

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

The variable name Ball2 should follow camelCase naming conventions. Consider renaming it to ball2.

Ball Ball3 = Lottery.getRandomBall();

Choose a reason for hiding this comment

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

The variable name Ball3 should follow camelCase naming conventions. Consider renaming it to ball3.

Choose a reason for hiding this comment

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

The variable names Ball1, Ball2, and Ball3 should start with a lowercase letter to follow Java naming conventions. Consider renaming them to ball1, ball2, and ball3.

System.out.println(Ball1);
System.out.println(Ball2);
System.out.println(Ball3);
}
}
Loading