• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Making Decisions Lottery application

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am stuck when it comes to writing this code. Everything I have had to do was an easy walk through, but know we are told to use psedocode to begin this before we actually write the application.

Create a lottery game application. Generate three random numbers, each between 0 and 9. Allow the user to guess three numbers. Compare cah of the user's guesses to the three random numbers and display a message that includes the user's guesses, the randomly determined three-digit number, and the amount of money the user has won as follows:

any one matching: 10$
two matching: 100$
three matching, not in order: 1,000$
three matching: 1,000,000$
no matches: 0

Make certain that your application accommodates repeating digits. For example, if a user guesses 1, 2, and 3, and the randomly generated digits are 1, 1, and 1, do not give the user credit for three correct guesses - just one.
Lottery-Output-example.jpg
[Thumbnail for Lottery-Output-example.jpg]
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Where's your code? What specific problems are you having with it? I'm sure you're not here to try and get someone else to write the code, right?
 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your on to me lol. I'm overwhelmed with this one. But as soon as I write some more if...else and && || . I will post this mess.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Breathe deeply a few times and tackle it a piece at a time. Like any other project, the whole shebang scan overwhelm you. Focus on each part until you get it working -- pretty soon the whole thing comes together.

When you post code, be sure to UseCodeTags to keep it readable.
 
Marshal
Posts: 79239
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as possible, you ought not to create a new Random object in the method. You should have the Random object as a field of the class initialised in the constructor, and as far as possible use the same Random object throughout. That is to obviate the risk (much smaller since Java5 than it was before) that two Random objects will return the same series of numbers.
 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I have written the output to the code so that it will display. My next step would be to input the random after the number choices. I also should be able to show invalid input if the user inputs a letter or number other than 0-9 so that it shows that they made an error. I will probably work on this fairly quickly, but the real trouble is awarding the prizes when the user matches the randoms and so on...

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David

First and only comment on your code. Push the code you have written so far into a method called readUserInput and call that from your main method which should be kept short in length.
 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I see what you mean by that... I just read the link about posting code and ShowSomeEffort . I will go back in my book and try to find out about the way we limit the numbers. As of right now I can only come up with for



I still seem to be able to write letters and int when I run it.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would personally recommend storing each user input number in an int[] array or a List rather than in separate variables. If you do the latter, you will have to hard-code all comparison logic using individual variable names. Arrays or Lists would make it much easier to extend the program to a situation where you had more than 3 digits.

Also, read the methods for Random here: http://docs.oracle.com/javase/6/docs/api/java/util/Random.html

That should help you figure out how to generate the random numbers internally.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about the pseudocode?
 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it is good practice to draw out the psedocode, kind of like directions for yourself. They said that programmers will use flowcharts, but we don't have the software, so I will have to write it out by hand.
 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written the Scanner for the three numbers that I can input for three different println lines. I made them only be int 0-9. But if user types a letter or symbol Java errors out. Would I have to include the input in my syntax for a variable so that it isn't true? A Boolean maybe?

 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, this forum is really keeping me motivated. It is making me really try to show everyone here that I can walk myself through this.

I thought I was alone out there with these questions. It is very nice to know that I can push myself to get these done without just walking away.
 
dennis deems
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Godwin wrote:I guess it is good practice to draw out the psedocode, kind of like directions for yourself. They said that programmers will use flowcharts, but we don't have the software, so I will have to write it out by hand.


And so you're writing the code first??
 
David Godwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a few sketches by hand, but this is just Introduction to programming. I see ahead that I can work on arrays and loops further on in the text, but I have to work this out with if if...else && and ||. We covered switch method and Conditional and NOT operators.
 
Ryan Sykes
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Godwin wrote:I have a few sketches by hand, but this is just Introduction to programming. I see ahead that I can work on arrays and loops further on in the text, but I have to work this out with if if...else && and ||. We covered switch method and Conditional and NOT operators.



That still doesn't negate the use of pseudocode. If anything, you should focus more on writing your pseudocode that explains the logic behind how you plan on tackling this assignment, rather than worrying about the syntax. If the logic is sound, the rest becomes a lot easier. So instead of posting code, why don't you focus on posting your pseudocode explaining the logic involved in completing this assignment. Assume that you have already parsed each of the 3 numbers from the user input and then try to figure out the pseudocode for getting the necessary output.

Also, if you haven't done loops yet, then checking the input for invalid input is not going to be very fruitful. As it stands, even when you detect a wrong input (number not between 0-9), the program proceeds to take the next input. You might be better off printing an Error message and using System.exit(0) to terminate the program. You could use loops to continue attempting an input till it is acceptable...but this is not so important. As I suggested...focus on the more important tasks at hand at try to write out the pseudocode here. If you are stuck in a specific section, folks might be able to assist you.
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic