CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2011
    Posts
    12

    Slot Machine Help

    Guys I need help finding out a few methods! I tried looking but I cant seem to find them!

    I need to know is how to print out 6 random numbers in a row!

    So for example I need to make it look like this but i need it to print random numbers:
    1 2 3 4 5 6
    4 5 6 6 5 4
    7 8 9 3 5 7
    7 8 9 3 7 7
    7 8 9 3 7 7
    7 8 9 3 7 7


    Also I need to know is the methods to tell if the numbers match
    - Vertically
    - Horizontally
    - Diagonally

    From there on I can develop it! Is anyone out there that can help? Please if you help me with this use really simple java programming language because I am just in grade 10!

    BTW I use Dr.Java

    Thanks!

  2. #2
    Join Date
    Jan 2011
    Location
    Tacoma, Washington
    Posts
    31

    Re: Slot Machine Help

    Hey there itonemod,

    Sorry I don't know what Dr. Java is. I could Google it but I'm not gonna. But your questions seem to be independent of programming environment and more about basic design and data manipulation.

    Glad to see a young programmer. However, if this for a school assignment (why else would you post your grade level) then the rules of the forum are such that no one should provide code for you. How can you learn if you don't struggle with it? =D I mean that in the best way.

    First off check out the Java API @
    http://download.oracle.com/javase/6/docs/api/

    I am in the 15.67th grade and I make extensive use of the API to find new info. It might seem a bit confusing at first but it is straight from the horses mouth. If you can't find it there then do some extra Google searches for what you need with "tutorial" or "example" after it.

    Now if it's random numbers you want then you need to know how Java deals with random numbers. Check the Java API and search for Random. Read about that and it should give you a heads up.

    Next you need to store the numbers. Will you use an array? An array of what type? There are other ways as well so you need to think about the design of the project.

    As a general answer to your question about how to compare values, you can compare vertical, horizontal, or diagonal. You can search in any direction you set your data up for. It depends on how many "dimensions" of your array (or other data structure) you have. So I'd read up on arrays and 2D arrays (I wouldn't worry about more than 2D array for now).

    Hope that gets you down the right path. Remember if programming was easy everyone would do it. So if you get stuck be sure to post where exactly you are stuck, what you are trying to do, what you think your program should do, and what concept you want help with.

    Good luck! =D

  3. #3
    Join Date
    Jan 2011
    Posts
    12

    Re: Slot Machine Help

    Haha thanks a lot! Ya it is for school but I don't want the code itself, I just need to know how I can get the methods mentioned above because I am really unfamiliar with them! If you guys can just provide me that part I can do it!

  4. #4
    Join Date
    Jan 2011
    Location
    Tacoma, Washington
    Posts
    31

    Re: Slot Machine Help

    I'm not sure what you mean by "the methods" to do what you want to do. Are you talking about a general algorithm for doing it or do you mean specifically the method calls that will give you random numbers in a block that checks for X in a row?

    In the first case check the Java API (follow link above and search for Random) for Random numbers and read up on storing values in arrays and multi-dimensional arrays. The check for X in a row will be a method that you need to write yourself.

    If you are asking for the correct combination of method calls to get you a slot machine then there is no such "combination". That would be programming.

    But generally speaking you need random numbers, some place to store them, and something to check to see if X in a row has happened. I don't think you will find a series of pre-made methods to call that will complete your assignment. Otherwise you could call:

    public SlotMachine my_machine = new SlotMachine();

    Somehow I doubt that would be the assignment though.

    Plus you don't want to use any code that someone on a forum gave you. If you can get it from the web then your instructor can find it as well. Instructors are like Santa Clause... They know... they just do...

    Good luck

  5. #5
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Slot Machine Help

    Create a 2D array int array (size = 6 x 6) and fill it with random numbers. djgarrison has given you the class to use to get the random numbers.

    You can then iterate over the array to output the numbers (hint: you need a for loop within a for loop - a nested for loop) and you can also use the array to search along a path ie horizontal, vertical or diagonal to see if the numbers match.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured