Coding And Playing The Lottery In Java - Full Tutorial with Source

preview_player
Показать описание
Let's create and play our own Lottery in Java!! We'll start by creating 6 random lottery numbers, then get the user's 6 lottery picks. Then we'll compare the winning Lottery numbers with the user's lotto numbers, and tell them whether they won.
If you can code this, play it, and win it (WITHOUT CHEATING), please let me know in the comments!

This is a beginner friendly Java coding lesson tutorial, where we'll create a full Lottery program from scratch.

Learn or improve your Java by watching it being coded live!

Hey, I'm John! I'm a Lead Java Software Engineer who has been in the industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java developers.

Let me know what else you'd like to see!

Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.

📕 THE best book to learn Java, Effective Java by Joshua Bloch

📕 One of my favorite programming books, Clean Code by Robert Martin

🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial

🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)

📹Phone I use for recording:

🎙️Microphone I use (classy, I know):

Donate with PayPal (Thank you so much!)

☕Complete Java course:

Рекомендации по теме
Комментарии
Автор

I enjoy your Java project tutorials! It’s been very fun and helpful thank you:)!

Catalyna.Salazar
Автор

You explain very well for beginners. Looked all your tutorials, and I understand now much more Java programming. Thanks! Only user input need contains numbers in this tutorial ;-)

alexundo
Автор

John this is awesome logic while u writing this code and explain what junior need to do. Thank you for this lesson, from Ukraine

pavelleshchuk
Автор

Hello John, I like the way you explain things. I always find something interesting in your tutorials, and it inspires me to search for my solutions before I watch yours figure out if you've found a better one :-)

However, I want to mention some things due to your solution:
1. It should also be a validation implemented to prevent the user from typing in the same value more than once (it's the same with the randomly generated numbers).
2. Maybe you could extract some of the code to separate methods to reduce the size of the implementation parts and use it again.
3. The numbers should be printed out in the correct sort order.

However, these were only minor things I recognised during the implementation of my solution and in comparison to yours. Anyway, I liked your implementation and explanation.
Thank you for that.

ToBa
Автор

Nice video, thanks John.
Is there a reason why you chose List instead of a Set ?

thomas_m
Автор

would this work for a bingo project in java?

Paranvirbeast
Автор

isnt it much cleaner at min 3:40 if you make an else clause with i--; so you dont need the while loop and break

fumano
Автор

At the end just check if the length of guessedNumbers is 6 instead of using containsAll...

ayazalvipro
Автор

hi john, i like your methodology.
I'm a beginner and would like to create different conditions for lottery
could you help me?
if I win I'll give you an amount😀

prototipagemmecanica
Автор

Great tutorial really helps in my project. Just one question, is oop the best practice especially if you are coding programs like this?

Nbak-cwjx
Автор

I enjoyed your awesome projects. please post more. It is interesting not boring like others. thanks bro.

bucky
Автор

why u did not use a Set data Structure instead of arraylist so that u will not have to check is the number is in the list of winning number or not
Set interface does'nt allowed duplicates

mikhailwiseman
Автор

Exactly what I am looking for but there is problem still need to fix. I do not how . winning numbers supposed to be in order, like 2 8 29 36 49 and separate no 6 not like 8 2 36 29 49. mega number between 1 and 29 .if this fixed would be great Sir, thx .

TheRainayan
Автор

how can I implement a method to create the entire list of number 1-49?, thanks

PedroRodriguez-qshq
Автор

Is it important to always close a scanner? Also, at 10:25, what would’ve happened if a user had entered the same number more than once? Thanks. 😊

findlestick
Автор

Hi John,
Great tutorial. Thank you. If there is a way to check matching elements and matching position of the 2 arraylist ? .contains only check matching elements in any position within the arraylist. Thanks 😀

yukij
Автор

How long would it take to brute force the winning numbers if the winning numbers and guessed numbers were picked as random by the program?

GJ
Автор

and of these possible how can I define a condition to eliminate them from these generated?

prototipagemmecanica
Автор

thanks man , its very easy to understand this code

ArkaArtworks
Автор

well you win lottery sir kn real powerball or megaball sir

yirehmiyahmagsayo